INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Problem deleting posts from trash My clients has recently had a problem with spam posts being added to their blog, under various usernames. The users have been deleted, but Wordpress is not able to remove the posts from the trash. Using the 'Empty Trash' button does not work either. Removing directly from the database appears to work, but as there are 4000+ entries this would take a long time. This is Wordpress v3.4.1 and has been upgraded recently. Can anybody help?
Technically, defining `define('EMPTY_TRASH_DAYS', 0 );` in `wp-config.php` file should delete whatever is in _Trash_ after zero days. I just tried it, but didn't work immediately. I may have to wait for a day to see the result.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "trash" }
is_user_logged_in() isn't working I'm making a login form for my site, and I've this section: <?php if (is_user_logged_in()) { echo 'Hello, ', $user_login, '. <a href="', wp_logout_url(), '" title="Logout">Logout</a>'; } else { wp_login_form(); } And after loggin in, it returns to the page with no indication of logging in. I suspect `is_user_logged_in()` isn't working, but I don't know how to debug this problem. EDIT: Whenever I do this: global $current_user; var_dump($current_user); I always get: ect(WP_User)#3 (7) { ["data"]=> NULL ["ID"]=> int(0) ["caps"]=> array(0) { } ["cap_key"]=> NULL ["roles"]=> array(0) { } ["allcaps"]=> array(0) { } ["filter"]=> NULL } No matter if i've 'logged' in with the above form.
There's nothing wrong with the function, it's the fact that you aren't actually being logged in! You say you're making your own login form? Does this post to the standard `wp-login.php`, or do you handle the request yourself? Does the path/domain of the form differ from WordPress? If you inspect your cookies, are any being set?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions, login" }
Change URLs depending on alias I have two domain names: themaindomain.com and thealias.com. Wordpress is located under themaindomain.com. I was wondering if it is possible to change the urls to posts and pages when there is a request from thealias.com To make clear: When there is a request from themaindomain.com, the server returns a page with some links like themaindomain.com/post1, themaindomain.com/page1. When there is a request from thealias.com, the server should return a page with some other links like thealias.com/post1, thealias.com/page1. So the two domains point to the same blog, but depending on the request url it changes the links. Is this possible and if it is, how? Thanks a lot...
You can use the the `WP_HOME` directive in your `wp-config.php`. Just set it dynamically based on `$_SERVER['HTTP_HOST']` like the example in the codex. <?php define('WP_HOME', ' . $_SERVER['HTTP_HOST']); You might also want to define `WP_SITEURL` in the same way. I do something like the above for the wp-content url on one of my sites: <?php define('WP_CONTENT_URL', '//' . $_SERVER['HTTP_HOST'] . '/content'); All that said, the SEO in me is screaming that this is a terrible idea -- duplicate content and such. Much better to have a single site and redirect the alias to the canonical site.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "urls" }
get_edit_tag_link does not return anything I'm trying to pull up a custom page which lists all tags used in my blog that have a description, to build up a glossary. It all works great but i would also like to display an "edit tag" link for each tag, only visible to admins. The built-in edit_tag_link() function is supposed to do just that, as far as i understand the codex, but the edit link does not show up. What is wrong with my code? $tags = get_tags(); foreach ($tags as $tag){ if(strlen($tag->description)>0){ $tag_link = get_tag_link($tag->term_id); print_r($tag); echo "<li><a class='content-link' href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'><h3>{$tag->name}</h3> <pclass='abstract'>{$tag->description}</p></a> ".edit_tag_link('edit tag','<p>','</p>',$tag)."</li>"; } }
Turns out the edit_term_link() function works fine for that. edit_term_link('edit tag','<p>','</p>',$tag);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "tags" }
How do I remove a pre-existing customizer setting? My theme doesn't use the tag line, how can I remove it from the customizer?
Late to the party but this will do the trick: $wp_customize->remove_control('blogdescription'); You want to remove just that control, not entire section as suggested above.
stackexchange-wordpress
{ "answer_score": 19, "question_score": 17, "tags": "theme development, theme customizer" }
Is wordpress Privacy Settings sufficient for this? I am going to import my current blog posts on to my future to-be self-hosted wp blog. It will take somedays before I make it the primay blog. In the WP Privacy Settings I have set "Ask search engines not to index this site" Is this setting enough so as to not affect my current page rankings? Or do I need to do something else may be messing with robots.txt or anything? Or are there any side-effects with this settings? EDIT: It says underneath: `"Note: Neither of these options blocks access to your site — it is up to search engines to honor your request."`
Install Authenticator. It requires a log-in to access the blog content. A `robots.txt` is just a recommendation and not safe enough.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "privacy" }
Sort wp_nav_menu() by menu order I have made a custom menu handler for the back end, sorting the via a drag drop based on CMS Page Order. The problem now is that it seems that it's not possible to sort wp_nav_menu in any other way than the default one, can that be really be true?
# The nav_menu_items are already sorted by menu_order. When you go into the Appearance -> Menus and arrange the order menu the menu_order of each menu item gets updated. To change the orderby parameter in the query that displays the menu you can use pre_get_posts to alter it. Example: add_action( 'pre_get_posts', 'wpse_sort_nav' ); function wpse_sort_nav( $query ) { if ( $query->is_main_query() && get_query_var( 'post_type' ) == 'nav_menu_item' ) $query->set( 'orderby', 'ID' ); } ID and menu_order are your only real options for sorting using the default post table. There is no title and the post_name is the same as the ID. You could add additional parameters to the pre_get_posts filter using the meta data stored with each nav_menu_item. Nav Menu metadata: _menu_item_menu_item_parent _menu_item_type _menu_item_object_id _menu_item_object _menu_item_target _menu_item_classes _menu_item_xfn _menu_item_url
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "menus, admin, wp admin, order" }
Convert post name into post ID I am trying to create a function for my functions.php file that will allow me to convert a post name into a post id. I have had a look around online and managed to find this link < which gives the following example.. function get_id_by_post_name($post_name) { global $wpdb; $id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$post_name."'"); return $id; } <?php echo get_id_by_post_name('my-post-name'); ?> After replacing **my-post-name** in the example I am not getting any results, can anyone suggest what is wrong? I was also looking into the get_by_postname function in case this was a better way of doing things.
Use `get_page_by_title()`. It works with any post type. $post = get_page_by_title( $post_name, OBJECT, 'post' ); echo $post->ID;
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "slug" }
Is there a list of all display functions for templates? I am going to write my own post display thing, and I cannot find a list of all these type of functions: the_date(); the_title(); the_excerpt(); I'm sure there are more, but where can I find a list?
**#1)** A doc for a function on **WordPress codex** lists all related functions at the bottom of the page. For example, this is the doc for `the_date();` — look at the section highlighted in the screenshot below: **Click on the image to enlarge...** ![Screenshot]( **#2)** Another very good reference is **QueryPosts**. When you search for a function on QueryPosts, you can presume that the search results are related to that function (at least in most cases). For example: **Click on the image to enlarge...** ![Screenshot 2]( Now, for the sake of relevance, here go the links to the pages for the respective functions where you can find other functions related to them: * **`the_date();`** — Codex, QueryPosts * **`the_title();`** — Codex, QueryPosts * **`the_excerpt();`** — Codex, QueryPosts And then there's Google. For e.g. `the_date();` on Google Search
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, references" }
Buddypress Filter Multiple Activities I'm trying to exclude activity updates (ones users actually post) from a custom "ticker" I'm running. With the below code, I am only displaying activities where friendships are created. How do I add another argument to allow for another activity action to display? <?php if ( bp_has_activities('action=friendship_created&max=5') ) : ?>
`<?php if ( bp_has_activities('action=new_forum_post,new_blog_comment,new_blog_post,friendship_created,joined_group,created_group,new_forum_topic') ) : ?>` Found the solution myself :)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "filters, buddypress" }
What is the purpose of this line of code in wp_trim_excerpt? Can someone please explain what the purpose of this code is: $text = str_replace(']]>', ']]>', $text); I'm referring to a line of code inside wp_trim_excerpt(), but I've seen something very similar in some other wp functions as well. On the surface, I would say it's not doing anything at all, but I have to give the wordpress developers more credit than that, so I'm sure there's a reason for this. I've looked into the php manual for str_replace to see if there is some special return value but everything is as I would expect. Is this some sort of ninja data validation technique?
The replacement string contains a HTML entity which when displayed on a browser, looks like the needle string. It's converting > to a HTML entity. Reference: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "core" }
Query post & loop problem. i having trouble while i added query to loop. please have a look whats the problem. here is the link <div class="fl" id="main_article"> <?php $count = 1; $the_query = new WP_Query( 'category_name=headline&orderby=post_date&order=desc' ); if ( $the_query->have_posts() ) : while (have_posts()) : $the_query->the_post(); if($count == 1) : ?> <a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title(); ?></a> <?php dynamic_excerpt(400); ?> <?php else : ?> <div class="post"> <a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title(); ?></a> <?php dynamic_excerpt(400); ?> </div> <?php if ($count== 2 || $count == 4 ){ ?> <?php dynamic_sidebar('index-insert') ?> <?php } ?> <?php $count = $count + 0; ?> <?php endif; ?> <?php $count++; ?> <?php endwhile; ?> </div>
no idea what the problems actually are, but from looking at the code, I woud suggest: a: the `while (have_posts()) :` should be `while ($the_query->have_posts()) :` b: you would need to increment the counter: `<?php $count = $count + 1; ?>` c: the `endif;` of the loop might be missing after the `endwhile;` \- at least it is not shown in the posted code section.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "loop, query" }
How to create a drop down list with pages to a themes options page? I'm building a themes options page using settings API. Everything is ok, but i now i want to create a drop down list populated with pages and i don't know how to! For example, i have this piece of code that show the list of pages, but when i select a page and cick on save, the page selected doesn't get saved! function combo_select_page_callback() { $options = get_option('journal_theme_blog_2_col'); echo "<select name='select_page'> <option value=''>"; echo esc_attr( __( 'Select page' ) ); ?></option> <?php $pages = get_pages(); foreach ( $pages as $page ) { $selected = '<option value="' . get_page_link( $page->ID ) . '">'; $selected .= $page->post_title; $selected .= '</option>'; echo $selected; } echo '</select>'; }// end combo_select_page_callback Thank for the help, nelson
I have found the solution. I used the wordpress function wp_dropdown_pages <?php function combo_select_page_callback() { $options = get_option('function plugin'); wp_dropdown_pages( array( 'name' => 'function plugin[ID used to identify the field throughout the theme]', 'echo' => 1, 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value' => '0', 'selected' => $options['ID used to identify the field throughout the theme'] ) ); } ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "options, api, dropdown" }
Can't Find BBPress data in Database I have installed BBPress in my Buddypress Based Wordpress Site. And i m unable to find any table of bbpress which contains data from the forum in my database. Where can i find it?
As far as I know bbPress uses custom post types. So all the data are in the regular `posts` and `post_meta` tables. A look at the source code should tell you more. From the bbPress Codex: > bbPress creates three custom post types and adds them to the navigation menu: Forums, Topics, and Replies. Use these menu items to create and manage your forums.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "buddypress, bbpress" }
Custom product fields in wp e-Commerce plugin I want the user to be able to set a text, option values or other type of data in each product just before they add it to the cart. Just like product options. > For example: The user buys a sticker and is able to set the text to be print I can't use product variations for this task before it is not about fixed values. Is there a way to add this type of functionality on wp e-Commerce plugin?
You can use WPEC Personalize plugin from here < It should do your job.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field, e commerce, plugin wp e commerce" }
How to make custom plugin run on demand? I'm trying to make a plugin which would run either by itself at a specific time or when it is triggered manually(that is, a particular function of the plugin is triggered). I'm not understanding how to implement that though and googling around hasn't been fruitful. If that may help, this is **briefly** how the function looks like. function rrikesh_insert_post() { $post = array([variables populated from external file]); wp_insert_post($post, true); } Anyone can suggest a way? Thanks
You can run scheduled events using wp_cron. To trigger it manually you'll need to create an admin screen and create a button that triggers the function. To do that read up on Creating a Plugin and Adding Admin Menus.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, plugin development" }
Search by word, category, tag, author I want to make a search page, offering search functionalities by: 1) word 2) tag 3) category 4) author Can you recommend any technique, any guideline as per how to tackle this?
You'll want to add some radio buttons inside your search form. Then add a filter to your search: function filter_search( $query ) { if( $query->is_search ) { if ( isset($_GET['tag']) ) // alter your search query here. } return $query; } add_filter( 'pre_get_posts' , 'filter_search' ); Influenced by <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "categories, search, tags, author" }
Override Current Theme Setting in wp_config.php I am looking for a way to override the currently selected theme, preferably from within the wp_config.php file. I know you can override some wp_options settings in the config like define('WP_HOME', ' This will override the 'home' option in the wp_options table. There is an option called 'current_theme' that stores the name of the currently selected theme. I'm wondering if there's a way to override this from the wp_config file and if so, will this actually change the theme. I've tried define('WP_CURRENT_THEME', 'someothertheme'); but it doesn't work. I need to do this in our development environment because the database is shared among two developers. I need to be able to work on one theme, while the other developer works on another theme.
Drop this in a plugin & activate. I should note this doesn't take into account things like child themes - it's purely for toggling which theme renders based on `SOME_FLAG`. add_filter( 'stylesheet', 'switch_ma_theme' ); add_filter( 'template', 'switch_ma_theme' ); function switch_ma_theme() { // Return the theme directory name return SOME_FLAG ? 'theme-1' : 'theme-2'; }
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "theme development, options, wp config, configuration" }
Total number of posts in query (category/tag/author/search results/main page...) I want to know the total number of posts from the category/tag/author/search result that I am actually seeing. Say for example I am in the main page. If my posts_per_page are 10 and my pagination shows 6 pages, that would mean there are a number of posts in my query between 51 and 60. How could I get that exact number? I would like it to work for every category,search results... from my web. Thanks in advance!
<!-- displays total number of posts for query, ignoring pagination --> <?php echo $wp_query->found_posts ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, pages, pagination, search" }
Would to use AJAX to get an option from the database and use it in a jquery setup or is there an alternative to consider? I have a slider in my theme. I have a setting in the options which controls whether that slider is set to "slide" or "fade". This slide/fade setting is in the jquery and of course the options setting is in the database. I presume the normal method of getting this setting is via AJAX but I thought I'd ask as I have a number of other similar scenarios on this theme. I always think of AJAX as meaning "change data without having to re-load the page" .... but in this case I just want jquery to have access the data when the page is first loaded ... so it seems my "understanding" is a bit off and jquery is needed for **any time** javascript/jquery needs to get info from the database.
Enqueue the script as you would normally, & then call the JS function right after the slider HTML output (or on `wp_footer`), and pass a JSON config back to the function. <!-- slider HTML --> <script type="text/javascript"> jQuery( "#my_slide" ).mySlider( <?php echo json_encode( $my_config /* array or object of arguments */ ) ?> ); </script> **Alternatively** , enter `wp_localize_script`: wp_enqueue_script( 'my-slider', plugins_url( 'js/slider.js', __FILE__ ), array( 'jquery' ) ); wp_localize_script( 'my-slider', 'My_Slider', array( 'somevar' => get_option( 'my_var' ), )); This'll output in the head something like: <script type="text/javascript">My_Slider = { "somevar": "value of get_option( 'my_var' )" }</script> <script type="text/javascript" src=" See how you now have access to the JS global `My_Slider`?
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "theme development, jquery, ajax, theme options" }
get attachment title based on attachment id I'm getting an image through `getMeta`. It returns me the id of the attachment. Now I want to get the titel, alternative text, description and so on. For the alternative text this works very well: get_post_meta($logo, '_wp_attachment_image_alt', true); Now I want to get the title. I found out I can do that with `$attachment->post_title`, but here I only have the id. How do I get the title for an attachment id?
If you have the attachment id, you can use `get_the_title()` $attachment_title = get_the_title($attach_id) <
stackexchange-wordpress
{ "answer_score": 41, "question_score": 22, "tags": "images, title" }
Change quick edit terms list to radio buttons is it possible to remove the current tax term checklist from the quick edit screen? i have switched the metabox for the "subject" taxonomy, to radio buttons, and would like to do the same in the quick edit box. i don't see any filters/hooks for changing the existing method, only an action for adding new items to the quick edit screen. is my only solution, therefore with javascript? quick edit only works w/ javascript enabled anyway. !screenshot of quick edit
I did solve this by setting the show_ui to false for specific taxonomies... but only on the edit.php screen. Then I added custom columns with my own custom quick edit to mimic the regular quick edit but using a custom Walker. If you add columns with a taxonomy name, WordPress automatically generates the quick edit, so you have to alter the taxonomy name somehow: I chose to prepend the taxonomy name with "radio-". The end result can be seen in my Radio Buttons for Taxonomies plugin.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "quick edit" }
Set post comments open function I've been searching high and low for a php function to set a comments of a given postID open only found function to check what the comment status is <?php comments_open( $post_id ); ?> I need one to set comment would expect it to be <?php set_comments_open( $post_id ); ?> But it isnt anybody got any idea what the function is or if there isnt one how to do it?
Have you tried go to **Posts** and checked the box next to the title and in the dropdown **"Bulk Actions"** choose **Edit** and then **apply** , Comments and in the dropdown **"Allow"**. And also have added the screen in the post edit area on the tab in the header called **"Screen Options"** and checked the field called: Discussion? And in **Settings->Discussion** have you enabled **"Allow people to post comments on new articles"**? **Add comments open to all posts** A filter hook called by the `wp_insert_post` function prior to inserting into or updating the database and update the post `comment_status` to open = true function comments_on( $data ) { if( $data['post_type'] == 'post' ) { $data['comment_status'] = 1; } return $data; } add_filter( 'wp_insert_post_data', 'comments_on' );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "comments" }
How to find the exact widget details I imported the blog to my self-hosted WP. I also found the theme I was using, downloaded and installed it. I don't see all the widgets that are available in my Wordpress.com dashboard. I can search for widgets e.g. Twitter but it gives me like 1000 results. I want exactly the one I have on my curren wordpress.com blog. Any ideas? Thanks
Try installing the JetPack plugin, which includes several of the .com features for your stand-alone blog. There's a Twitter widget in there that might be the one you were using.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "widgets" }
Can't query by meta_key For some reason. I do not have the ability to query by meta_key when I run a loop. What could cause this and what can I do to the diagnose the problem? I am using wordpress 3.4.1. $args = array( 'meta_key' => 'slideshow_image'); $query = new WP_Query($args);
Thanks for @dunc and @helgatheviking I got the answer. Here's my code. You need the post type declared, otherwise it resorts to "post". I also couldn't do this unless I put meta_key and meta_value in a 'meta_query' multidimensional array. $args = array( 'post_type' => 'tsa_events', 'meta_query' => array( array( 'key' => 'slideshow_image', 'value' => array(''), 'compare' => 'NOT IN' ) ) ); EDIT: you can also structure your query this way: $args = array( 'post_type' => 'tsa_events', 'meta_key' => 'slideshow_image', 'meta_value' => array(''), 'meta_compare' => 'NOT IN' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom field, wp query, loop" }
Display comments of users on single page I don't know if i can explain this.. I want to create a Page where the comments of specific user is listed. like this format... ## User Name Post Tilte - comment - comment - comment Post Tilte - comment - comment - comment well, im not looking exactly as that format, but I want something similar to that. I already have a page where all the posts by specific user is listed, now this time I want list of comments. Is that possible? Or is there any available plugin that can provide me that function? Any answers or recommendations will be appreciated. Thanks :)
### You can use the get_comments function to retrieve comments from a specific user. $comments = get_comments( array( 'user_id' => 1 ) ); foreach( $comments as $comment ) { $post_id = $comment->comment_post_ID; $post = get_post( $post_id ); setup_postdata( $post ); echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>'; echo $comment->comment_author . '<br />' . $comment->comment_content; }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "plugins, posts, comments, plugin recommendation" }
Generated URLs don't reflect accurate URLs. Evening, I'm getting some incorrect links generated by my theme. `WordPress Address (URL): `Site Address (URL): Clicking on something like `preview post` Generates a URL like this: ` The correct URL is: ` How can I make it reflect this? (Also, I cannot change site Address because my site is in a different subdomain)
> **Site Address (URL)** > Enter the address you want people to type in their browser to reach your WordPress site. This is the directory where WordPress's main index.php file is installed. The Site address (URL) is identical to the WordPress address (URL) (above) unless you are giving WordPress its own directory. WordPress will trim a slash (/) from the end. If you defined the WP_HOME constant in your wp-config.php file, that value will appear in this field and you will not be able to make changes to it from the WordPress administration screen. 1. Either change Site Address (URL) to: ` 2. Or copy index.php into localhost/newgameplus and change `require('./wp-blog-header.php');` to `require('./wordpress/wp-blog-header.php');`
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "url rewriting, subdomains, domain mapping" }
"about us", " contact" sections should be article(post) or page in the simple small Business website? I am new in WordPress i am rails programmer that need to do for small Business only WordPress website with : main page, about us, contact + few articles(posts) that will be in the main page "about us", " contact" sections should be article(post) or page in the simple small Business website? Thanks,
It's totally up to you to decide to put it as a post or a page. I would put it as a page though. One important difference between them is that Pages are hierarchycal and Posts chronological. You can study each in the Codex to better decide: * < * < This can also be usefull: * <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "posts, pages, customization" }
Forum plugin that allows private groups that are invite only I'm looking for a plugin that would allow me to create private groups for discussion that are invite only. These would be for people who have taken a workshop and want to remain in communication with their cohort afterwards. They would need to be invited/added by admin after each workshop and would not communicate with other participants. Anyone have any ideas? Appreciate the help!
You can easily create private forums with the Simple:Press forum plugin. < It can do a LOT more than just that, and for that reason might be overkill (not sure what other requirements you have), but if you are looking for a very flexible and powerful forum system, then I can recommend Simple:Press.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 4, "tags": "plugins, private, forum" }
RSS Feed has no styles in chrome - function to add one? This is a really bizarre problem. For some reason Chrome does not have any RSS feed formatting? Where as most other browsers do! So it seems from I read online that I have to create my own style sheet for it :/ That's fine, but how can I add my RSS stylesheet to my wordpress RSS feed without manipulating the core files. Is there a function that will allow me to add this style sheet? Thanks for any tips :-)
I'm not sure this is a problem you really need to solve. Any regular Chrome user knows this is how Chrome (doesn't) handle RSS. That said, you can provide a custom feed template. see Customizing Your Feeds in Codex.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "functions, rss" }
Echo a numerical value in query_posts I am creating an option page for one of my wordpress themes and I am trying to ask user to enter "Number of posts to show" - I am using "query_posts" to show posts This is the code I modified but it is not working `<?php query_posts("posts_per_page='".of_get_option('numberofposts', '3' )."'&cat='".of_get_option('postcategory', 'no entry' )."'"); while(have_posts()) : the_post();?>` the correct method to echo the option used is : `<?php echo of_get_option('numberofposts', 'no entry' ); ?>` which returns a value the user entered - ex : 5 the category section works , I can output the category ID but not the number of posts . thanks in advanced
You have the value of posts per page in single quotes, remove the quotes and it will work. That said, you should be altering the main query with `pre_get_posts` instead of `query_posts`.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "query posts" }
Is it possible to override the default Gallery Settings form? I'm trying to change the options that are presented for the gallery settings. I can't seem to find a hook or override that gets exactly what I want. I came close with the following, but it only seems to add to the top of the tab. function media_upload_gallery(){ echo 'test'; } add_filter('media_upload_gallery', 'media_upload_gallery'); Is it even possible to hook into that form and either replace it or edit it? Levi
There is no way to alter the gallery settings. About the only thing you can do is to override the entire gallery shortcode. You can technically have your users pass any sort of parameters into the shortcode and recognize them with your alternate gallery. Simply use: add_filter('post_gallery', 'foo_override_gallery', 1, 2); function foo_override_gallery($empty, $attr){ //Extract the attributes //Create your own gallery layout return $output; } By returning any value to the filter, the default gallery is completely overridden. You must **return** HTML for this to work properly. I know this isn't exactly what you're looking for, but it's the closest way to customize the output of the gallery shortcode. I dumped the gallery template here sans the override filter that you could put in your new function: < Hope this helps.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "filters, gallery" }
Best Practice for Server Processing In a theme I have a form that I need posted and some work done on the server. What is the recommended way of doing this? I have it posting to another php file where some work will be done, and then redirected back to the previous url. I'm having some issues with this because all the functions that normally work in a page don't anymore; such as `home_url()` and `get_current_user_id()`. Is there a good/easy way to include the basic WP things to use? Does the php file need to be a wordpress page? Is this even a good way doing this?
I recommend you take a look at the AJAX in Plugins page which should solve your woes with redirects. < You can send whatever you want to be processed asynchronously. This is a pretty standard way of processing forms in WordPress both on the front-end and back-end. If you need to include user data, add the current user ID to the jQuery.post data array to be sent to your AJAX hook.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development" }
if custom posts type exists and there are posts load script I have registered a custom post type `'featured_post'`. I am looking for a way to test if the blog home page has any `'featured_post'` posts on it and if it has load a javascript file. The 'featured_post' posts will make a slider at the top of the blog home page. I had this working using sticky posts but I can't work out how to conditionally load the script if there are posts of CPT 'featured_post'. This is the code that worked for sticky posts: if ( is_front_page() && is_sticky() ) { wp_enqueue_script ('flexslider-js'); } However this does not seem to work and I don't know why: if ( is_front_page() && get_post_type('featured_post') ) { wp_enqueue_script ('flexslider-js'); } Thanks in advance.
I'm at work at the moment (sorry boss), so I can't test this, but the snippet below should be the proper way of testing if the 'featured_post' post type exists, and then enqueue the script if it has any posts. if ( is_front_page() && post_type_exists('featured_post') ) { // We are at the front page, and the post type 'featured_post' is registered. $hasposts = get_posts( 'post_type=featured_post' ); // lets check if there is any posts in the 'featured_post' post type. if( $hasposts ) { // If we found some posts, lets enqueue the script wp_enqueue_script ('flexslider-js'); } }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, wp enqueue script, conditional tags" }
Is it good idea to combine Options FrameWork with Hybrid Core Framework (This is my first time posting here, so would appreciate if anyone could let me know the best way to post questions). Until now, I had been using TwentyEleven Theme and adding "Options Framework - < It works great and I wish to continue using it. However I found a better base theme Hybrid Core ( through which I could better management my development. I wanted suggestions if its good to combine "Options Framework" & "Hybrid Core" for theme development considering Hybrid already has its own way of adding meta boxes to the Theme Options page.
Unless Options Framework has some gnarly features that knock Hybrid out the water, I would simply... move on ;) Taking the time to learn a new framework beats the hell out of the idea of merging & then maintaining two - I just think it'd cause more headaches in the long run than it might solve at the beginning.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme options" }
Automatically remove trashed pages from nav menu As it is now, when a page that is in the nav menu is trashed, it still stays in the menu until manually remove via the nav menu editor. Is it possible to have trashed pages removed automatically? Thanks
Just hook the default `delete_post` handler for menus onto the trash action too: add_action( 'wp_trash_post', '_wp_delete_post_menu_item' ); How simple is that!
stackexchange-wordpress
{ "answer_score": 10, "question_score": 4, "tags": "menus, pages, automation" }
For what queries is conditional tags informative? I think it's great to use conditional tags but if the query is slightly advanced it won't give information about the original query. For example; is_category('apple') _might_ give a false response if "banana" AND "apple" has been queried. This is because is_category() compares against one single category and doesn't bother about the rest. I need a way to know when I can expect that conditional tags won't give complete information about the original query. Can someone explain the limits of wordpress conditional tags?
> is_category('apple') might give a false response if "banana" AND "apple" has been queried you're using `is_category` incorrectly in this context. From Codex: > is_category(); // When any Category archive page is being displayed. A category archive page is for a single term, if a query is a for more than one term, it's not a term archive page. so it's not a matter of "giving complete information" it's a matter of understanding what each tag actually indicates.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "wp query, conditional tags" }
Copying over taxonomy structure from one CPT to another I have a CPT called adverts and it has 2 taxonomies - category and location. The problem is that there are about 100 entries in location taxonomy and I need to copy the same structure to another CPT - businesses. Doing everything manually will take forever. Are there any solutions for that? P.S. Taxonomy structure includes parent and children hierarchy P.P.S. I checked the DB structure and due to its design it is hard to find all relations and taxonomies there as they are in various tables. Maybe there some kind of a plugin?
When you register the taxonomies you can specify multiple post types: function register_my_taxonomies() { register_taxonomy( 'location', array('post','page', 'adverts', 'businesses'),
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, taxonomy" }
programmatically adding categories to custom taxonomy wp_create_category() adds new categories to the 'content' taxonomy associated with the post type... Simple question really neither wp_create_category() or wp_insert_category() allows configuration for taxonomy type... so how can I can do it?
For custom taxonomies you should use wp_insert_term()
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "categories" }
What are ideal hooks to call register_sidebars? Where should a plugin ideally hook to call `register_sidebar();`? Will `init` do just fine? function my_plugin_register_sidebars() { $args = array( 'name' => 'foo' 'description' => 'bar' ... ); register_sidebar( $args ); } add_action( '**????**', 'my_plugin_register_sidebar' );
Twenty Eleven and Twenty Twelve use the `widgets_init` action. Given that these themes are generally considered to use best practices for theme development, I think this hook would be ideal.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "plugins, hooks, register sidebar" }
How to skip woocommerce checkout out page? I use woocommerce plugin for my shop. I want to skip the checkout page where users give shipping details. So the system will be when they select a product and after go to the cart page they will go to paypal and from paypal we will get the adress. Any idea how i can build this, Please help me. I am newbie.
there is an option in the Woocommerce to not include shipping Go to Woocommerce > Settings> Shipping and disable the options there !Woocommerce Settings
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugins" }
Generate a WP post from Youtube Feed Normally when you get a Youtube feed, it will display the description/title from the YT video. However, I want a post to be generated when a new video is posted on YT so that an admin/editor can go back and change the title or add a teaser.
If working with wp_insert_post and the youtube api is too much work, or too complicated, you may be interested in the plugin called "Automatic Youtube Video Posts" (AYVP). It has been working quite well for us. There are some bugs (nothing critical) and it is not the most efficient plugin, but it does exactly what you need and if you need a quick fix it does the job well enough. Writing a custom plugin is still on my to do list, due to the efficiency concerns and because AYVP isn't exactly what we needed, but thus far it is close and good enough to keep that from becoming a priority.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "youtube" }
How can I get category ID by category name? I have a few categories with the same name [some of them are sub-categories]. And I want to get an array of ID's for certain cattegory name. I tried this: $term = get_term_by('name', $cat_name, 'category'); but it seems that `get_term_by()` returns only the first term that match the query.
Use `get_terms()`, which uses `WP_Term_Query` under the hood. For a full list of all the available parameters check out the documentation for `WP_Term_Query::__construct` // Get term *IDs* with name that *matches* "my_name" $term_ids = get_terms([ 'fields' => 'ids', 'taxonomy' => 'category', 'name' => 'my_name', 'hide_empty' => false, ]); // Get term *objects* with name that *matches* "my_name" $terms = get_terms([ 'taxonomy' => 'category', 'name' => 'my_name', 'hide_empty' => false, ]); // Get term *objects* with name that *contains* "my_name" $terms = get_terms([ 'taxonomy' => 'category', 'name__like' => 'my_name', 'hide_empty' => false, ]);
stackexchange-wordpress
{ "answer_score": 13, "question_score": 5, "tags": "categories, terms" }
AJAX call fails when sending JSON but works with URL style string When making an AJAX request is works when my data is a URL style string. var options = { type: 'post', data: 'action=my_action' }; The function will get called and return some fake data just fine. If I try to make the same call but use JSON, it doesn't work. I've tried several different ways of doing it, but admin.php just return -1. Is there something in jQuery or Wordpress that I need to change to allow this? Here are a couple of the other ways I've tried. var options = { type: 'post', data: { action: 'my_action' } }; var options = { type: 'post', data: JSON.stringify({ action: 'my_action' }) }; The example in the docs have it using a JSON object too. <
Firstly, `stringify` won't build a URL query - it _serializes_ it into JSON object notation. And secondly, you don't even _need_ to build the URL query - if you're using jQuery to make the AJAX call, just pass the JSON object as it is - `jQuery.param()` will internally handle it :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, ajax" }
Access tinymce from thickbox Basically, I have a custom tinymce button which opens a thickbox window in iframe mode. Is there a way to access the tinymce from the iframe? Wordpress media uploader seems to do it somehow. Stuff like `$('#content', window.parent.document).tinymce().getContent()` does not work. PS. If that's impossible, I'll have to do use the tinymce default popup window, but Good God it's ugly.
tinyMCE isn't implemented as a jQuery plugin. I'm not sure, but this would be more probable: window.parent.tinyMCE.get('editor').getContent()
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "tinymce, thickbox, iframe" }
How to rename 'TAG' to 'TOPIC' i want to rename TAG to TOPIC and url it should be wordpress.stackexchange.com/tag/ to wordpress.stackexchange.com/topic/ is it possible ?
**Click on the image to enlarge.** ![screenshot]( The screenshot shows the **Permalinks** settings screen. To do what you want, specify **topic** in the **Tag base** field/box.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 1, "tags": "tags" }
special characters after saving draft interpreted as � I am trying to create posts in hindi language. These characters `UÉeÉMÑüqÉÉU` after saving/publishing are interpreted as `UeMqU`. Though, the special characters are stored with no change in the mysql database. The `` symbol is only during retrieving. I'm stuck here. The post editor is modified to intake multiple posts. < I tried commenting these lines in wp-config.php. But none worked. /** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'UTF-8'); /** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', ''); Also, placed `mysql_query("SET NAMES utf8");` in wpdb class constructor of wp-db.php. Negative, even this didn't work How do i overcome this?
Its utf-8 character encoding problem. Fixed it using the function utf8_encode(): utf8_encode(html_entity_decode($mb->get_the_value()));
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "wp admin, metabox, post meta, wpalchemy" }
Image resize depending on orientation? is there an option or a plugin that resizes an image depending on it's orientation? Reason for this question: Im building an image grid and it would look even better when all images would have the same width.
If you need the images to be the same width but varying heights (ie not 300 x 300 but 300 x anything) then in settings -> media add 9999 to the height of whichever image size you want to use. You can also define your own custom thumbnail using the same principle: < [EDIT] As @brasofilo suggests, you can also use 0.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "images" }
Are there risks associated with using wp_options table using wpdb to update theme options I am making a theme and it has so many options that need to be updated via jquery's ajax.Having looked at ways of updating wp_options via ajax,i have hypothesised that updating the wp_options table would be the easy way out for me. Are there risks if update the options that way or is it safer to go the api way?.
Updating options via pure SQL is wrong. 1. If you feel you have too many options to use the regular API you probably have too many options at all. A theme should not do the job a plugin can do. In fact, it should do as little as possible and let the user choose a plugin for simple tasks. Examples are fields for tracking codes or sharing meta data. 2. Store your options in **one** array under a single option name. The API will serialize it for you. Exceptions are options you need on de/activation only like the theme version. 3. If you use the API plugins can hook into `pre_get_option_*` and extend or change what you do. Don’t break that, you cannot know what your users need.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "wpdb, options" }
How to dispaly post informations (such as titles) in an admin plugin menu page? I'm trying to develop a WP plugin to show post(or page) related information (such as show all post title in a list) in an admin menu page. I tried to use "The Loop", but it seems like "The Loop" cannot be accessed in Dashboard. I have achieved my goal by using $wpdb to query database directly. But is there a better or safer way to load post information in a dashboard menu page? Thank you in advance.
It was my mistake, the loop can be accessed in the admin panel
stackexchange-wordpress
{ "answer_score": 2, "question_score": -2, "tags": "plugins, plugin development, loop, wpdb" }
How do I change the author of a custom post type? I have made a custom post type and need to be able to create posts and assign them to authors. It is easy to do this with posts as you can go to the bulk edit screen and immediately change the author. However, when I try to do this with my custom post type the author box is not there. How do I add the functionality to change the author of my custom post type? EDIT: I found a solution, see answer below.
I found out that the edit author attribute is not added by default in for custom post types. To add the author attribute the following code is required: function allowAuthorEditing() { add_post_type_support( 'mytype', 'author' ); } add_action('init','allowAuthorEditing');
stackexchange-wordpress
{ "answer_score": 7, "question_score": 13, "tags": "custom post types, plugin development" }
How do I pass data from page content to the underlying PHP template Pretty much all of the content on the site is going to be dynamically generated (php + db backend) What is the preferred "wordpress way" of passing data to a php template (set up as a template in a wordpress theme) So the template would be something like <?php generate_content_based_on_this_variable(page); ?> and I'd need to be able to pass it `page` for each different page * * * Edit 1 So I have a page that, for simplicity, looks something like this > Hi everyone, this is page X The content here is generated from a db call: > > SELECT * FROM db WHERE page=X > > [Spit out db resultset here] and the template would be something like <?php the_content() $query='SELECT * FROM db WHERE page=X' $result=$db->execute($query) foreach($result as $row){ echo $row } ?>
If you want to produce a page in WordPress whose structure and content are dynamically generated independent of the regular posts handling mechanism then: 1. Create a new page with title " **My Custom Page** ". This generates the page slug '`my-custom-page`' by default. 2. In the root of your active theme folder eg. _\wp-content\themes\twentyeleven\_ create a page template for this new page named `page-my-custom-page.php`. 3. Put your custom php code inside the page template. 4. Navigate to **your-site.com/my-custom-page/** to see the results
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "pages, templates, page template" }
How can I install my custom-made theme on a wordpress.com blog? I've only ever worked with WordPress on my own server. I'm using wordpress.com for my development environment, but I can't for the life of me figure out how to upload my themes since as far as I know I have no FTP access... I'm sorry if this is something that should be obvious, but all I'm finding in searches is how to FTP themes into personal WP installs, which I already know.
This is what Wordpress.com says: > Because of the way WordPress.com’s technical infrastructure is designed, we are not able to support uploading of custom WordPress themes on our service. You are only allowed to pick from pre-existing themes.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "theme development, themes" }
Form submit from modal window to parent window Trying to submit a field value from a popup modal window to my WordPress parent window meta-box. On my add post page I have a metabox with a field type 'text'. !Meta-box The id of my 'text' field type input is 'tumble2_kaltura-video' Next to the metabox text field is a button link which opens up a modal box: !Kaltura popup window Once I select my video in the modal box, there is a submit button that when clicked will send out a shortcode. _Normally this shortcode is sent to the wp-editor_ !shortcode output to editor What script do I need to use in order to send the shortcode from the modal box to the metabox text field 'tumble2_kaltura-video'? Here is my kaltura code that is 'in charge' of normally sending the value to the editor. Need to change something in here to target my metabox instead. < I tried pasting my code in here instead of gist, but no matter how I formatted it, it was always messed up.
Use the **parent** method to pass data back to your meta field. Create a JS function to handle the passing of data from Thickbox to the meta field: function foo_interstitial(data){ $('.form-field-selector').val(data); } Add a submit handler to your thickbox instance that passes to the parent.foo_interstitial() function. $('.thickbox-submit-selector').submit(function(){ var _value_to_pass = $('.field-to-pass-selector').val(); parent.foo_interstitial(_value_to_pass); });
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "metabox, shortcode, forms" }
Hook that fires when admin setting is saved Is there any specific hook that fires when admin setting is saved. I have cached some data from admin back-end setting menu. Now i want to the delete the caching when setting saved in admin menu. Thanks in advance for help.
There is the _filter_ `'pre_update_option_' . $option`. You have to know the option name. Options can be updated from front-end too, so WordPress doesn’t make a difference here. Then there is an _action_ : `'update_option'`, you get the arguments `$option`, `$oldvalue` and `$_newvalue`. Finally, if the update went successful, you get two further actions: do_action( "update_option_{$option}", $oldvalue, $_newvalue ); do_action( 'updated_option', $option, $oldvalue, $_newvalue ); See the source code of `update_option()` for details.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 7, "tags": "hooks" }
Wordpress and Unity high scores table I am trying to figure out what is going to be my best route to go in this choice. I have a Unity game I have integrated with Wordpress but I need to send and receive the high scores of the game in the WP database. 1. Should I create my own table in WP to store my high scores along with the user information of people who have signed up. 2. Should I use Custom Post Types to store this kind of information instead of a my own table in WP? Many thanks
I'd use a custom table for this. Otherwise you'd have to have a lot of custom post types posts containing very little information. Your own table is easier to manipulate (and, god forbid, export should you want to use another high score solution).
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, custom taxonomy, database, users" }
wp_register_script Question I need to add the following JS to the head, but I don't know how to add the "data-cfasync="false" " by using "wp_register_script" or "wp_enqueue_scripts". Please help!! <script data-cfasync="false" type="text/javascript" src=" <script data-cfasync="false" type="text/javascript">try{Typekit.load();}catch(e){}</script>
If you need to add it in the `head`, then this might help you: <?php add_action('wp_head', 'add_attr'); function add_attr(){ ?> <script data-cfasync="false" type="text/javascript" src=" <script data-cfasync="false" type="text/javascript">try{Typekit.load();}catch(e){}</script> <?php } ?> Make sure your theme has the `wp_head` function call. You'll need `wp_enqueue_scripts` or `wp_register_scripts` only if your JS code in in some other `.js` file and you need to call it on some page.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "jquery, javascript" }
Transient api Caches confused This code works for page 1 <?php $paged1 = (get_query_var('paged')) ? get_query_var('paged') : 1; $recent1 = get_transient( 'recent1' ); if ( false === $recent1) { $recent1 = new WP_Query ('cat=3&posts_per_page=5'.'&paged='.$paged1); set_transient('recent1', $recent1, 60*60); } // do normal loop stuff if ($recent1->have_posts()) : while ($recent1->have_posts()) : $recent1->the_post(); ?> <div id="line"><a href="<?php the_permalink () ?>" rel="bookmark"> <h2><?php the_title (); ?></h2> <?php the_post_thumbnail(array(100,100), array('class' => 'alignleft')); ?> <?php the_advanced_excerpt(); ?> But there is a problem with pagination. Page 1 confused with page 2 or page 3 and etc. On page/2 there is content of page/1 or on the contrary. How to resolve this ?
"This code works" - but it doesn't! If you're gonna cache paginated posts, you'll need to store them chunked: if ( ! $my_paged = absint( get_query_var( 'paged' ) ) ) $my_paged = 1; if ( ! $my_query = get_transient( "recent_$paged" ) ) { $my_query = new WP_Query( "cat=3&posts_per_page=5&paged=$my_paged" ); set_transient( "recent_$paged", $my_query, 60 * 60 ); }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "wp query, loop, query, cache, transient" }
Adding columns to core tables I was just wondering if there is a compelling reason to not let a plugin add columns to a core WordPress database table, such as wp_term_taxonomy. I could always create a separate table and join it to the WordPress core table, but I would prefer to keep the additional data that my plugin uses in the standard WordPress tables. Is there a downside to using this? Could I expect stuff to mysteriously start breaking?
# Two Problems **Problem #1** \- You shouldn't ever change the default schema that ships with WordPress. This schema might change in the future (entire tables could be dropped and re-built in an update). **Problem #2** \- You shouldn't really be creating new tables in the first place. If you create a new table with your plugin it might work just fine in a single installation. But what about Multisite? What if it's network activated by mistake? Now you're not creating 1 new table, but potentially thousands of new tables on some installations. # A Different Question The question you _should_ be asking isn't of what to do with the tables, it's where to store the data. Why not use a custom post type to store your custom data? There's almost always another place to put your data that doesn't require you to add tables to the database.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "plugin development, database" }
WordPress | Date not always appear > **Possible Duplicate:** > WordPress the_date() not working I try to create a theme. In that theme I have create a custom post type and I quering the WordPress by using the wp_query to get the posts from that post type with the code that following : $args = array( 'post_type' => 'portfolio', 'posts_per_page' => 18 ); $projects = new WP_Query($args); while($projects->have_posts()) { $projects->the_post(); ?> <h3><?php the_title(); ?></h3> <span><?php the_date(); ?></span> <?php } wp_reset_postdata(); the problem is, that while I get the title for all of my posts, I do not get the date for all of my posts. Some posts have the date, other they don't Any idea for that issue ?
Use `get_the_date()` instead, here's note from `the_date()` codex page regarding the issue: > When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "wp query, loop" }
Apply Filters Causing a 500 Internal Server Error I have a custom post type and need to display it in a certain way. I would like other posts to display as normal. When I tried to use the following code to accomplish this, I get a 500 Internal Server Error. global $post; //do this only for custom type if (!(get_post_type()=='customt')) { $rawContent = $post->post_content; $formattedContent = apply_filters('the_content',$rawContent); echo $formattedContent; return; } I have googled around and found a lot of things regarding .htaccess but I don't think that is the case here. If I comment out the apply filters line (`$formattedContent =...`) and echo raw content, the post displays, but without formatting of course. What am I doing wrong when I am trying to apply a filter?
Please try to replace your snippet with the following. The `global $post` isn't needed, when it's outside a function or method context and inside the loop, as then `$post` is already `global` and `get_post_type()`s default `false` arg with be replaced with `$post` inside the function. if ( 'customt' !== get_post_type() ) return print apply_filters( 'the_content', $post->post_content ); Also make sure, that you're not calling it on some too early filter, like `plugins_loaded` or `init`, as the global `$post` object wouldn't be setup up.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin development, filters" }
shortcode using multiple WP_Query's with multiple category names not fully functional we're working on a bilingual site, Larry A. Downs all the posts are categorized into two categories, english or spanish, along with other categories. so every post has multiple categories, i've coded out a shortcode that sets up a tabbed widget in the sidebar, based on the language category, using multiple WP_Query's and looping thru them, but if you look on the english category page: /category/english some the queries are returning posts from the spanish category, i've checked the posts and they're in the right categories, i think i'm not setting up my query $args properly, and could use the wisdom of higher lever wordpressers than i. thanks again stack. here's the sidebartabs shortcode: SidebarTabs Shortcode
As of WordPress 3.6 you can put comma-delimited entries in the category_name property of the arguments array like this: $args = array( 'category_name' => 'news2014,news2015', ); query_posts($args); This works if the categories are both at the root level (no parent)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp query, shortcode, query" }
Enqueue jQuery UI Tabs In Admin Area Does anyone know how to enqueue the script "Jquery UI Tabs" in admin area? I want to use it inside my theme options page. Already read the related wordpress documentation but with no results... I have added UI Tabs to the front-end and works fine but I cant add it in the admin area... Thanks in advance.
I normally load it as a dependancy of my plugin's js file like so: if ( is_admin() ) { //load my plugin's js add_action('admin_print_scripts', 'my_plugin_load_js' ); } function my_plugin_load_js() { $plugin_js = WP_PLUGIN_URL . '/' . plugin_basename( dirname(__FILE__) ) . '/my-plugin.js'; wp_enqueue_script('my-plugin-js', $plugin_js, array('jquery-ui-tabs'), '1.0'); }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "admin, jquery ui" }
Can a Plugin Override New User Default Role Type I'm making a plugin that creates user accounts. Is there a way I can create new users that get the role that I (the plugin developer) tell them to, as opposed to making them all the default new user role. I want to make new users a role type that is defined by my plugins parent plugin.
You can use the `user_registration` action to set a custom role directly after wp_insert_user() has been called. add_action('user_register', 'foo_set_new_user_role', 9999, 1); function foo_set_new_user_role($user_id){ $user = new WP_User( $user_id ); $user->set_role('your_new_role'); } You can also use the action `profile_update` for just that, profile updates. It takes two parameters `$user_id` and `$old_user_data`. Hope this helps you out.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, plugin development, user roles" }
how to get current user name by user_id in buddypress? I want to display the user names by the reference of user id. Is there any function like get_user_displaynme($userid)? (and one more Is there any shortcode to get group names?) Thanks in Advance
You can use the very same `get_userdata` function of WordPress to code a specific function. Stick this in your `functions.php`: function get_display_name($user_id) { if (!$user = get_userdata($user_id)) return false; return $user->data->display_name; } So you can do something like: $display_name = get_display_name($some_user_id); echo $display_name;
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "buddypress" }
Entire VPS locks up when using particular theme I have a VPS with, so far 2 osCommerce websites, and it was running fine. I then installed Wordpress 3.4.1 and it was fine as well. I tried a free theme from the theme installer called Hero, and every 30 or so page loads the entire VPS locks up. Not just the apache or PHP or MySQL, but I can't even access the server via SSH. This is on a test server with 2gb of ram and almost no other visits than my own. Theme: <
Usually the first step is to make sure there is no problem by changing the theme to Twenty Eleven and running the 'same steps' to recreate the problem. Some themes may not be ready for Wordpress 3.4.1 as it introduced a lot of theme related changes. So see if there is anything on the WordPress.org page for your theme of on the theme developers website. Failing that you can ... 1. download again the theme from WordPress.org, in case your zip was corrupt 2. choose another theme 3. contact the theme developer via the theme page on WordPress if you really want to use that theme
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "themes, vps" }
Front End Plugin for User Management Is there a free plugin that I can use for a membership site which includes user login, registration and profile management all from WordPress front end? Thanks
Yes ... there are lots of plugins for this scenario You could just enable BuddyPress which gives you a 'social network in a box' then there are these two plugins s2member WPMU membership lite failing that ... read through the related articles on here for suggestions
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugins, plugin recommendation, membership" }
What is the Timeline for the Active Version Pie Chart in the Repository? When going through your own plugin details and checking the active version downloads. It's helpful to see which version that webmasters prefer, but I see no details on the subject on WordPress (and on here, yet). I recently had an unexpected change in stats, and I can't find anything as to what the time frame is. What few that I have found are either closed with little or no response, and/or indirectly related. The active version pie chart can be found on any plugin under **Stats**. Most of the time, new versions don't even show up until about a day or so, but is the timeline based on days, weeks, or months? This says that it is based on the current active users. Which is interesting. Daily Tip: New Usage Graphs on WordPress.org Plugin Repository Any additional information on how the chart actually works is helpful.
The active version pie chart is made up of completely nonsense data that isn't being updated properly at present. What it displays has absolutely no bearing to real-world data. It's on my list of things-to-fix, eventually. Once our stats gathering system is more reliable, I'll do so. However, at present, it is total nonsense. Ignore it.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin development, statistics, repository" }
Thumbnail informations (meta) Does anyone know how can I display in the loop thumbnail's name, alternative text, title, caption, url? Thx for all advices and suggestions
Try the following code inside the loop and modify it as per requirement. $thumb_id = get_post_thumbnail_id(); echo 'Name = '. get_post_field( 'post_name', $thumb_id ).'<br />'; echo 'Alt = '. get_post_meta( $thumb_id, '_wp_attachment_image_alt', true ).'<br />'; echo 'Title = '. get_the_title( $thumb_id ).'<br />'; echo 'Caption = '. get_post_field( 'post_excerpt', $thumb_id ).'<br />'; echo 'Description = '. get_post_field( 'post_content', $thumb_id ).'<br />'; echo 'SRC = '. wp_get_attachment_url( $thumb_id ).'<br />'; echo 'URL = '. get_permalink( $thumb_id ).'<br />';
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "thumbnails" }
What program can I use to preview my wordpress site? Apologies if this is the wrong site to be asking this, but I just downloaded a template for a website that I want to customise. On my Mac I have a program called Espresso which allows me to 'preview' any website that contains any mix of client-side and server-side files. Is there an equivalent on the PC? I essentially just want to preview my website offline.
You should install any program - for example MAMP \- that allows you to use Apache and MySQL. Then go to wordpress.org and download the latest copy of WordPress. Install it and upload your theme in the `wp-content/themes` folder.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "theme development, previews, offline" }
Sort by post word count in admin area I have a custom post type called `species` which consists of a number of `meta_fields`. Ideally, what I'd like, is a word count for each `species profile` (that's just the term I use for a singular post of type `species`). So, for example, when you click the `Species` menu in the back-end, you can see a list of all the species profiles (paginated, as WordPress does) with information about how many words are in each `species profile` and to be able to sort by that `ASC`/`DESC`. If I was doing this outside of the back-end area I'd probably do the following: * Retrieve all of the data for the specific `Post_ID` * `strip_tags` the data (and WP's shortcode tags) * Put it all in a big string * Use `$array = explode( " ", $string )` to create a large array * Get the word count from `sizeof( $array )` Question is, how can I put this into the WordPress admin area for this post type? And how do I make it sortable? Thanks in advance,
I think your best bet is to hook save_post and save the count for each post to a meta field. It's not feasible to do the calculation when the back end is loaded, every post will have to be queried and sorted in memory. Likewise, doing it all in MySQL will require some significant query modification, and still then you won't be able to remove shortcodes and markup from the numbers. as far as the columns and sort are concerned, there are several answers here on how to do that, start with the Related questions column to the right. Also see this post by Scribu on the subject.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, wp admin" }
get current category ID php I'm trying to get category ID of the current archive displayed. I tried: // category (can be a parent category) $current_cat_ID = get_query_var('cat'); // print_r ($current_cat_ID); It doesn't print anything...
you can use `get_queried_object()` $category = get_queried_object(); echo $category->term_id;
stackexchange-wordpress
{ "answer_score": 57, "question_score": 17, "tags": "php" }
How to develop a community feature in the dashboard for multiauthor site I run a Wordpress site that has more than 300 authors. Is it possible to create some type of community in the backend (dashboard)? Ideally, a space where the authors can discuss with each other in a thread type of system, with admin news and so on. The closest thing I could find was the Admin Microblog but by reading the description, it appears very limited. I am quite surprised that there is not much backend community type of plugins, I would have imagined that the demand for such would be rather high. Anyone knows?
What I do for almost every site with multiple authors: 1. Create a separate blog for meta discussions, for example `meta.example.com`. 2. Use P2 as theme. 3. Install Authenticator to allow access for members only. 4. Install something like Inform about Content, so the members get an email whenever something new was posted. I probably wouldn’t do that for 300 members … You could write a dashboard widget with the newsfeed for the meta blog like the _Incoming Links_ and make it a MU Plugin to set it active on every new blog. This works rather good; it requires almost no configuration, and even people with low technical skills understand it fast.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "plugins, admin, author, dashboard, community" }
How to add post featured image to RSS item tag? **I am able to add a post featured image to the RSS feed like so:** function insertThumbnailRSS($content) { global $post; if(has_post_thumbnail($post->ID)){ $content = ''.get_the_post_thumbnail($post->ID, 'thumbnail', array('alt' => get_the_title(), 'title' => get_the_title(), 'style' => 'float:right;')).''.$content; } return $content; } add_filter('the_excerpt_rss', 'insertThumbnailRSS'); add_filter('the_content_feed', 'insertThumbnailRSS'); However, upon examining the XML generated for the RSS feed, I noticed it sticks the featured image into the XML description item tag. How can I insert post featured image into it's own RSS feed item tag of let's say "image", rather than just inserting it in with the post's content?
You could do it by adding an action to the hook 'rss2_item' like so: add_action('rss2_item', function(){ global $post; $output = ''; $thumbnail_ID = get_post_thumbnail_id( $post->ID ); $thumbnail = wp_get_attachment_image_src($thumbnail_ID, 'thumbnail'); $output .= '<post-thumbnail>'; $output .= '<url>'. $thumbnail[0] .'</url>'; $output .= '<width>'. $thumbnail[1] .'</width>'; $output .= '<height>'. $thumbnail[2] .'</height>'; $output .= '</post-thumbnail>'; echo $output; });
stackexchange-wordpress
{ "answer_score": 12, "question_score": 10, "tags": "post thumbnails, rss, feed, xml" }
issues with wp_enqueue_script in my plugin So I am working on a plugin and am trying to trigger a js file whenever a post is saved. I have been reading up on this all morning and cannot seem to find why this is not working. Any advice? If I were to paste the js code directly into the plugin it seems to work... I have double checked the path to the js and still no response. add_action( 'admin_init', 'plugin_admin_init' ); function plugin_admin_init() { wp_register_script( 'qtool-insert-v2', plugins_url() . '/buildStatus2/' . 'qtool-insert-v2.js' ); } add_action( 'save_post', 'add_my_script' ); function add_my_script() { wp_enqueue_script( 'qtool-insert-v2' ); } Here is the qtool-insert-v2.js - very simple redirect. <script type="text/javascript"> <!-- window.location = " //--> alert("HELLO"); </script>
You need to hook into admin_enqueue_scripts with your add_my_script function. < Example: function add_my_script() { wp_enqueue_script('qtool-insert-v2'); }add_action( 'admin_enqueue_scripts', 'add_my_script' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, wp enqueue script" }
Redirect members to custom page upon logging in through WP admin When a members logs in through WP admin, I would like to redirect them instantly to a custom URL. What will I need to change to make this possible? Respond with step-by-step details would be ideal.
I use this plugin It works dandy for setting different redirects for each role and even user capabilities.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 3, "tags": "customization, wp admin, redirect" }
Get post ID in post/page edit area How can i get "post id" in post edit area for add_filter in functions.php? I want to change file name automatically during upload. so i need to obtain post id. the code is as follows: add_filter( 'wp_handle_upload_prefilter', 'custom_upload_name' ); function custom_upload_name($file) { list($name, $ext) = explode('.', $file['name']); $file['name'] = $post_ID.'.'.$ext; return $file; } Edited: the final and working code: add_filter( 'wp_handle_upload_prefilter', 'custom_upload_name' ); function custom_upload_name($file) { $post_ID = $_POST['post_id']; list($name, $ext) = explode('.', $file['name']); $file['name'] = $post_ID.'.'.$ext; return $file; }
Try using $_POST['post_id'] in the upload area as file.php does not include the global $post object.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "posts, admin" }
How to have different content in the loop and single < Try to look at this famous site which also powered by wordpress. The content in the loop is different from the single post. It use "dl" element in loop, but not main content in the single post. It something like it has a another brief summary of a post that will only display in loop. So my trouble is how to display something(include image,article,video embedding) in the loop of multiple post but not display in single post itself, and vice versa.
you can add additional information to your posts through using post meta: < If you want to check if Wordpress is going to display just a single post/single page or more, you could use something like this before your loop: $single_page = false; if(is_single() || is_page()) $single_page = true; And then in your loop you can simply write conditional code like: if($single_page == true) echo 'single page';
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, loop, single" }
How do I pass the value from a foreach loop to an add_filter function? I'm trying to add multiple filters from inside a foreach loop. Unfortunately I can't get the code to reference the value properly. How do I pass the value from the loop to the function? The following sets all the filters to null. foreach ( $myarray as $key => $value ) { add_filter( "plugin_filter_$key", function( $value ) { return $value; } ); } This is my test code and this sets the filters to 'true'. foreach ( $myarray as $key => $value ) { add_filter( "plugin_filter_$key", function( $value ) { return 'true'; } ); }
foreach ( $myarray as $key => $value ) { add_filter( "plugin_filter_$key", function () use ( $value ) { return $value; } ); } Check out the `use` keyword for closures.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "filters" }
Custom Post Type, Saving Multiple Checkboxes For a custom post type, I'm pulling in a list of another custom post types that I need to select for saving ... <input type="checkbox" name="32"> My CPT <br> <input type="checkbox" name="41"> My CPT 2 <br> <input type="checkbox" name="42"> My CPT 3 <br> <input type="checkbox" name="43"> My CPT 4 It's easy enough to save a single input, but how do I save multiple checkboxes? update_post_meta( $post->ID, 'mycpt', $_POST['myinput'] );
You will need to save them as an array and currently your HTML is not in the correct format to do this. <label for="my-cpt-32"> <input type="checkbox" name="cpt_ids[]" value="32" id="my-cpt-32" /> My CPT #32 </label> <label for="my-cpt-41"> <input type="checkbox" name="cpt_ids[]" value="41" id="my-cpt-41" /> My CPT #41 </label> <label for="my-cpt-43"> <input type="checkbox" name="cpt_ids[]" value="42" id="my-cpt-43" /> My CPT #43 </label> When this get's $_POST'ed you will have an array of checked values, make sure to check it is 'set' e.g. `isset( $_POST['cpt_ids'] )`. If you ticked 41 & 43 you would get array like this: array( [0] => 41, [1] => 43 ) which you can use to save in your custom field, or a secondary table etc. I hope this helps!
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "custom post types, post meta, customization, input" }
Why should I password protect WP-Admin? Just occured to me: what's the point of password protecting www.yoursite.com/wp-admin when a user can just type www.yoursite.com/wp-login.php, bypassing the password on /wp-admin? Am I missing something here? I've ready many blogs/posts that suggest adding this extra layer of protection to wp-admin using .htaccess/.htpasswd.
The protection from .htaccess is for the folder `/wp-admin` it's not for the URL Open up your ftp programme (or download WordPress) and look inside /wp-admin By only allowing your IP access this folder you're blocking a lot of possible exploit issues (as mentioned in comments below). I always prefer to login at `mysite.com/wp-admin` and not login.php this way, if you're still logged in to your site, you go straight to the Admin section.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "wp admin, htaccess" }
Link listings with image So I'm really new to Wordpress and I'm trying to create a simple widget. I want the widget to list the logos of my site's affiliates (similar to the "check out our shows" section on < I also want it to be easy for the administrators to add/remove images from the list of partners. In other words, I don't want to have to modify the widget's code in order to change the partners. At a very high level what are the steps that I might follow to build this widget?
Why not use Links Categories? There you can use images, descriptions, create categories and sort out everything. There would be no need to create a widget as you can use the default WordPress one. !links widget Case you were to create your own widget, you can query these items with WordPress functions.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "images, widgets" }
How to manage a big collection of files with wordpress? I have a collection of nearly 3000 swf files that will be used in some of WP's post. Two options that I can think of-- 1. Upload them to WP Media Library,they'll become attachments, I can query attachment to get them. 2. FTP to host, create database table, query them directly. Which way would you recommend?
Your best bet is to go with option 2 and alter the DB or use a plugin like < I can't imagine uploading 3k large files through a http interface like the WP uploader. A 3rd and probably better option is to just use a CDN like amazon to host the media files, since WordPress sucks at this type of thing,
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "uploads, attachments" }
Returning all radio button options when using Advanced Custom Fields When using the Advanced Custom Fields plugin for Wordpress, Suppose I have a radio button field with possible choices: o Apples o Bananas o Cranberries How can I return each one of these options regardless of which one is selected? Thanks everyone
Check out this page in order to discover your field key for your radio button: < Next, insert this code where you are grabbing your field values: <?php $key = 'your_fieldkey_here'; $field = get_field_object($key); if ($field) { foreach ($field['choices'] as $key => $value) { echo ('KEY : ' . $key); echo ('<br />'); echo ('VALUE : ' . $value); echo ('<br />'); } } ?> This code will return your set of keys and values. This only issue with this method is that it will not work if your radio button field is inside of a repeater field.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "advanced custom fields" }
List all the tags from a custom post type I'm looking for solution that will display all the tags that are used on a custom post type. I just want to list them all because I'm going to add jQuery code on each tag. :)
wp_get_object_terms will have your answer. `wp_get_object_terms( $post_ids, 'post_tag', $optional_args );` There is also get_the_terms which is simpler but also gets the job done. `get_the_terms( $id, 'post_tag');`
stackexchange-wordpress
{ "answer_score": 10, "question_score": 9, "tags": "custom post types, custom taxonomy, tags" }
Wordpress stylesheet isn't being added I have recently started to learn WordPress and after learning how to use it at basic level I immediately started to learn how to develop templates since this is what interested me from the start when I started to learn it. I am reading WordPress 3 Complete and at Chapter 6 the book guides you to develop your first basic theme. The only problem is that it seems that my theme is not taking the style sheet. I have tried to use: <link rel="stylesheet" type="text/css" href="style.css"/> and <style type="text/css">@import url("style.css");</style> None of them seem to get the style on the page. What should I do?
You have to make sure WordPress finds the directory where your theme is. There is a useful function doing all the work for you: `bloginfo()`. <link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "theme development" }
Wordpress widget which displays archive tree I'm a complete newbie, so would appreciate some help. Is there a wordpress plugin that can display all posts/archives as a part of a tree structure? With high-level parents being `year` and children being `month` Something like this, -2012 ---Jan ---Feb ---Mar . . . . -2011 ---Jan ---Feb ---Mar ..
Since you're a beginner I would like to mention that WordPress already has an archive widget. If ever it does not suit your needs, You can browse through the available archive plugins at wordpress.org and choose which one is the best for you.
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "plugin recommendation, archives" }
How to show a post single post in page template Currently I've divided posts into 5 different categories, based on the categories I've created 5 page templates. all of the pages are listed into the home page navigation menu. in my home page I'm showing 5 posts in five different categories. when they clicked a post that post will shown in the single page template(that's what word press normally does) but i want to show that post into my page template. because each page template having different designs. if there is any way to set the permalink to point to the page template and show the post in to full.
The »Template Hierarchy« doesn't allow this per default. Inside your `single.php` template, you can call `load_template()`. This will allow you to simply include the template you need, based on the `in_category()` conditional tag. // inside single.php if ( in_category( 'foo' ) ) { load_template( get_stylesheet_directory().'foo_template.php' ); } elseif ( in_category( 'bar' ) ) { load_template( get_stylesheet_directory().'bar_template.php' ); } elseif ( in_category( 'whatever' ) ) { // ... }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "page template, homepage, single" }
Removing custom meta box added in parent theme I am using a child theme, and wish to change one of the meta boxes defined in the parent theme. The meta box is for 'pages' only. I tried using the remove_meta_box in my functions.php, but it has no effect: function remove_parents_box() { remove_meta_box( 'id-of-meta-box' , 'page' , 'normal' ); } add_action( 'admin_menu' , 'remove_parents_box' ); Any ideas? **Addition to question:** I found that the parent theme uses: add_action( 'admin_menu', 'lala_create_meta_box_page' ); add_action( 'save_post', 'lala_save_meta_data_page' ); To initiate this meta box. As I wish to create the meta-box with my own code, should I actually remove it by something like: remove_action( 'admin_menu', 'lala_create_meta_box_page',999 ); And then create my own meta-box?
_Note: This is the merged version between my and @toscho answers._ ### Explanation (by @toscho) Use `add_meta_boxes_page` as action hook. You can find the hook in `wp-admin/edit-form-advanced.php` and it displays as: do_action('add_meta_boxes_' . $post_type, $post); ### Solution(s) Try the following action, which is inside `register_post_type()` as well. function wpse59607_remove_meta_box( $callback ) { remove_meta_box( 'id-of-meta-box' , 'page' , 'normal' ); } add_action( 'add_meta_boxes_page', 'wpse59607_remove_meta_box', 999 ); If you know the exact position where the action, that adds the meta box is registered, you can also just remove this one. function wpse59607_remove_meta_box() { remove_action( 'admin_menu', 'lala_create_meta_box_page' ); } add_action( '_admin_menu', 'wpse59607_remove_meta_box', 999 );
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "metabox, child theme, pluggable" }
How to modify the query to exclude posts by slug? How can I modify my query in order to exclude certain posts by slug? Is it possible? query_posts(array('category_name' => 'Mycat', 'posts_per_page' => -1)); Ty
You can get the post ID from the slug with the `url_to_postid()` function: $ID = url_to_postid(slug); then just exclude the ID from your query: query_posts(array('category_name' => 'Mycat', 'posts_per_page' => -1, 'post__not_in' => $ID )); You can create an array of post IDs if you need to exclude multiple pages.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "query posts, query" }
Editor Styles and Typekit My website uses typekit to grab custom fonts, which works on the frontend. I'd like to put this in my editor styles in the backend. However, I don't know how I would do this. Typekit uses a js embed snippet rather than a css font-face embed snippet.
Tom Nowell's TinyMCE plugin solution works brilliantly, just update the JavaScript to use Typekit's new async code. Once you use the new async embed code, the 403 problem disappears and you'll have Typekit-enabled TinyMCE with no fuss! Tom has put all the code together in a blog post. He did all the heavy lifting on this, so go give him some pageviews and read the specifics there!
stackexchange-wordpress
{ "answer_score": 3, "question_score": 10, "tags": "admin, editor" }
Redirect to 404.php from single.php I have a situation where I want to redirect the user from single.php to my 404.php How can I do this? I did it like this inside single.php header("HTTP/1.0 404 Not Found"); header("Location: ".bloginfo('template_url')."/404.php"); exit(); **But when I check the http responses I get a 302 response instead of the 404** **Important: it may not work because I have a post called "cars" which I use to custom generate pages like:** The post is just: The rest are just php query strings which were rewrited using add_rewrite_rule. So is rewrited into: And sometimes the variable bmw is not inside my database, and I want this page to get a 404 response.
Try something like this: header("HTTP/1.0 404 Not Found"); $wp_query->set_404(); //This will inform WordPress you have a 404 - not absolutely necessary here, but for reference only. require '/path/to/404.php'; exit; Just do the error handling on the page itself instead of redirecting it to another template. This will maintain your 404 header and give you complete control right within the parent template.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "redirect" }
Any advice on customising this twitter feed? I'm really having trouble locating the documentation for the Recent Tweets widget anywhere. It's not a plugin and appears to be native. All I want to do is to be able to move the `tweet_time` underneath the `tweet_text`. If you take a look at the website, you'll be able to see the time of the tweet is on top of the actual tweet text, and I want to reverse the order.
It's part of the Webzine theme \- if you take a look at the source, near the bottom, there's a rather hefty chunk of JS that queries Twitter & renders the tweets. Now whether that code is sat there waiting for you in `footer.php`, or called in from somewhere else, I don't know - if the latter, you'll have to root around the theme folder to find it! It's worth mentioning that the Twitter user status API is loaded _again_ (along with Twitter's own `blogger.js` for the callback) at the very bottom of your site, but it's not actually utilised - you could save yourself some processing (& headaches for that matter) by removing it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "widgets, twitter" }
WPTouch - how to remove shortcodes or make shortcodes function So as the title states - using WPTouch Mobile plugin (NOT Pro) I either want to make the shortcodes work as they should or remove them altoghether. Currently they render on the page as `[shortcode]` which is no good. I am good with a hack or any other solution.
I think you mean you want to make your own short codes work on the mobile theme? This is possible, try the wptouch admin panel options to enable your plugins. You can also copy your short code to the functions.php file in the wp touch theme folder. Finally ... You may have to get the pro version of wptouch so you can develop the shortcode support.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, shortcode, mobile" }
List Table API - Safe to use? Just curious what developers think about extending the `WP_List_Table` class for use on plug-ins. I am working on a plug-in that will show a list of users (ID, name, email) then pull data from another plug-in that created a subscription date and access level in the user meta table. The plug-in will be in the admin area of WP and only available to administrators. I was hoping to use the class to be able to select multiple users and edit the data of multiple users at one time. Is the class safe to use in this case or should the table be re-created?
Its not a private class, only its methods (some) are defined as private so as long as you extend the class and use your own instance of theme extention you should bs safe and fine.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "api, wp list table" }
how do you prevent showing a particular category on the admin dashboard for specific user roles? I'd like to prevent the "Featured" category from appearing for certain user roles. To be specific, I want only the admins and editors to be able to see and thus select or unselect that category. Everybody else can see the whole tree but the Featured cat. Which hooks and WP API do I need to tap into in writing the necessary plug in?
Based on the first Answer from Mike Schinkel. For testing purposes in a default installation, the category is "Uncategorized". add_filter( 'list_terms_exclusions', 'wpse_59652_list_terms_exclusions', 10, 2 ); function wpse_59652_list_terms_exclusions( $exclusions, $args ) { global $current_screen; if( 'post' != $current_screen->post_type ) return $exclusions; if( !current_user_can('delete_others_pages') ) return $exclusions; return $exclusions . " AND ( t.name <> 'Uncategorized' )"; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin development, dashboard, categories" }
How to make a Discussion Group ”Sticky” in BuddyPress Discussion Groups sort on activity. Is it possible to make them sticky to always appear on top of the list? Thanks.
To summarize: OP wanted to make an entire BuddyPress Group sticky, which is not possible currently in core BP. You can add this functionality using the Group Meta custom fields and then hooking into the BP Group Loop.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "buddypress" }
Give a function a unique ID I'm developing a theme that uses a Twitter Tweets custom widget (Not coded by me). There are several widget areas within the theme and if I try and include the Twitter widget in say the sidebar and the footer at the same time I get this error; Fatal error: Cannot redeclare echo_tweets_js() (previously declared in..... on line..... This is the section of offending code; function echo_tweets_js() { global $pt_twitter_username, $pt_twitter_postcount; echo pt_twitter_js($pt_twitter_username, $pt_twitter_postcount); } add_action('wp_footer', 'echo_tweets_js', 9999); Is there a way I can make it work if a user decides they want it in 2 places at the same time?
Just... call the function again - you only need to include it once! include './path/to/lib.php'; echo_tweet_js(); // a little tweeting here ... echo_tweet_js(); // and a little tweeting over here!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions, widgets" }
Is there any pre-existing plugin to track and block IPs with suspicious activity on my site? The image below shows a recent (failed) attempt to crack my Wordpress install. It's easy for me to look at that and see what they were doing, but is there a plugin that exists that monitors this data and can catch events like this? Especially for something as blatant as this, I would like to block the IPs, but it's not exactly practical for me to sit watching IP activity 24/7. Thoughts? !enter image description here
I use < which blocks IPs when login attempts exceed set limit you set. > Limit Login Attempts blocks an Internet address from making further attempts after a specified limit on retries is reached, making a brute-force attack difficult or impossible. If you're on a host where you can install and run root code, look at < > "Fail2Ban monitors log files like /var/log/pwdfail or /var/log/apache/error_log and bans failure-prone addresses. It updates firewall rules to reject the IP address or executes user defined commands."
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, security, hacked" }
Hiding an added admin page menu using css I have added an admin page in wordpress but i needed it to be hidden.I added the page successfully like this function add_admin_page() { $themename = 'Cesaro'; $page_function = 'admin_page'; add_menu_page($themename." Options", $themename, 'edit_themes', $page_function, 'admin_page'); } add_action('admin_menu', 'add_admin_page'); To hide it,i looked at its css using firebug and discovered a pattern or so it seems.Pages added in the format i demonstrated have a css id that starts with #toplevel_page_{page_added} so the css id to the page i added is #toplevel_page_admin_page. I went ahead and did #toplevel_page_admin_page{ display:none !important; } Is this format #toplevel_page_{page added} consistent with all wordpress installations?.
WordPress already takes care of that for you. The third argument in your `add_menu_page` function, which reads `edit_themes` is the capability required to access the page. If the user doesn't have that capability he can't access the page, so WordPress won't show him that option on the menu. Clever, no? Now, from the code you mention on your comments, you're restricting the page to user who can `edit_posts`. If that's what you want, just use that on the `add_menu_page` function instead. Otherwise, it doesn't make sense. PS: If you're planning to add a theme options page, I'd suggest using the add_theme_page function instead, which will nest it within the Appearance section of the menu.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "admin menu, options" }