question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
How does DD32's tool determine the WordPress version of an installation. Its not working fine for WP 3.1 but it doesn't uses meta generator tag or the readme.txt of WP. So what else can it be?
I'm just assuming here but this is usually done by fingerprinting for specific version files/directory's/code and sometimes even size. For example you can remove all the meta versions tags ( isn't there like 12 places) and .txt file for 3.1 but since 3.1 is the only version to include the following new file by default, it is rather easy to fingerprint. <code> wp-includes/js/l10n.js </code> Since each release has many new additions, if you spend enough time writing a smart bot, it not very hard to find release specific data. Hiding all this info would be a lot of work for every release.
Remotely identify the version of a WordPress installation?
wordpress
I am going to submit my first plugin to the repository. How do I find out the Requires tag value for which my plugin would work? I know its somewhat vague, but how do you guys figure out? Like my plugin just add some info in the head section. The only thing required for its functionality is <code> wp_head </code> hook. So I just did a grep and checked the inline documentation that it was introduced in WP v1.2 So am I right? This is how I should be doing it? Any tips?
Yepp, if you really only use that hook, that would be the way to go. But it's pretty likely you also use a couple of WP functions...if so, you should check these functions, too, before going too low with your required version. Generally, i wouldn't go below 2.0 (which i smore than 5 years old) for any new plugin. I think even going lower than 2.5, which is about 3 years old, is unnecessary.
Find out Requires WP tag for a plugin when submitting it
wordpress
How do I "download" all my photos from my media library to my local computer? I can do this one at a time, but is there a way to grab them all at one time? Sort of like a "download all" process.
Your best way of doing that would be downloading the wp-content/uploads directory, by ftp access.
how to download all media files into my computer
wordpress
I have some custom code that sits inside <code> &lt;head&gt;&lt;/head&gt; </code> . When I install a new WordPress theme I have to edit the <code> header.php </code> script each time. Is there a way to always include my custom code inside the head tags even when installing a new WordPress theme?
You want to create a new plugin for this. See: http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head Create a new file in /wp-content/plugins/ called headerstuff.php (or whatever) Drop the following code in it: <code> &lt;?php function header_code() { $output .= ""; //code segment echo $output; } add_action('wp_head', 'header_code'); ?&gt; </code> Add your code between the quotation marks on the line starting with "$output". Activate, done!
How can I show some standard html code across any theme I install?
wordpress
On this search results page: http://p2reloaded.com/?s=versions&amp;search-submit=Search I'd like to inverse the order of the results to start by newest post date first at the top of the page. Right now it's showing older posts first. Is there a way to specify that in the WP search function through a URL parameter? BTW, I am had to install the Relevanssi plugin to get WP (or the theme?) to search using tags. Thanks! Noel
WordPress will order search results by newest post first by default, so if your results are in a different order then it looks like another plugin is affecting them. Have you tried searching with all other plugins disabled? If you're using Relevanssi, then it won't order results by date as Relvanssia overrides this with its own weighting algorithm instead (which is the whole point of using Relevanssi).
How to have search results page sorted by post date
wordpress
Can WordPress be used through Google Sites? Instead of creating a blog at WordPress itself, I considering to make a mesh of a website and blog using Google Sites and WordPress source code, but I'm not sure how to do this or even if it's possible. What do you think?
Because Google Sites does not have databases sorry you have to use another site. Also becuase I don't think they have PHP on them.
Google Site and WordPress
wordpress
I want to display the direct category ancestor of a given post. An illustrative example: These are the categories I have: Cat1 Cat2 Cat2.1 Cat2.1.1 Cat2.1.2 Cat2.2 Cat2.2.1 Cat2.2.2. Cat2.3 Cat3 Cat4 I only put the posts in a single category between a same "level", but when the category has more sub categories, I check the whole trailing, like in: Cat1 [X] Cat2 [X] Cat2.1 Cat2.1.1 [X] Cat2.1.2 Cat2.2 Cat2.2.1 Cat2.2.2. Cat2.3 Cat3 Cat4 Now, in the single post page, I want to display the name of the direct category ancestor of the post (Cat2.1.2 in this case). By default I just use <code> get_the_category() </code> , but it shows the top level category instead (Cat2 in this case). I don't considerer unchecking top levels by now because it cause another problems within the template.
It is possible that <code> get_the_category() </code> will always return the categories in the correct order (with the deepest at the end), but if it doesn't, you could also loop over all the categories and remove those where another category points to it as their parent. <code> $post_categories = get_the_category(); $categories_by_id = array(); foreach ( $post_categories as $category ) { $categories_by_id[$category-&gt;cat_ID] = $category; } foreach ( $post_categories as $category ) { unset( $categories_by_id[$category-&gt;category_parent] ); } // $categories_by_id will now only contain the deepest categories </code>
Display only deepest category on a single post?
wordpress
Say I buy a hosting package with GoDaddy and they allow 1GB max databases. So my question is how can I combine and use 2 DB's in WordPress? Is there a plug=in or do I need to edit the wp-config.php file? Benny, Age 12.
1GB is quite large, you won't get there too quickly. Furthermore, there's plenty of cheap hosting plans out there with unlimited db size. Doing what you want is in theory possible by hooking into the <code> query </code> and a whole bunch of other filters, but it's pretty complex, as you will hardly know which db to query to get certain records unless you also keep a meta database. Even then you'll still often have to query both databases and then merge the results by hooking into further WP hooks. You get the picture.
How can I use more than 2 DB's
wordpress
When I assign a post to two categories always one of categories becomes the main category. Is there any way to specify which category out of the two or more is the main category not a secondary category?
If by "main" category you mean the category that is used to create the permalink, the default is to use the category with the lowest ID . You can access the post also with an URL that contains another category, but the <code> rewrite_canonical() </code> function will kick in and redirect you to the "canonical" URL with the "main" category. However, if you hook into the <code> get_permalink() </code> function and return a URL based on another category, the canonical rewriter will notice this and it won't redirect. So you will need to create a UI in the post creation screen to select the "main" category, and hook into <code> post_link </code> to create URLs with this category.
If a post belongs to two categories how do I choose the main category?
wordpress
i'm listing all posts of my custom post type "person" alphabetically sorted by the custom field <code> last_name </code> on a page. How would i insert a divider (e.g. an image of the letter) before a letter range starts? Here's what i'm trying to do: Update: Here's the code i'm using: <code> &lt;ul class="list-ensemble"&gt; &lt;?php query_posts('post_type=person&amp;post_status=publish&amp;meta_key=last_name&amp;orderby=meta_value&amp;order=ASC'); if ( have_posts() ) while ( have_posts() ) : the_post(); ?&gt; &lt;li data-id="&lt;?php the_ID(); ?&gt;"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" class="ensemble-single-link"&gt; &lt;?php if ( has_post_thumbnail() ) { the_post_thumbnail(thumbnail); } ?&gt; &lt;/a&gt; &lt;/li&gt; &lt;?php endwhile; // end of the loop. ?&gt; &lt;/ul&gt; </code>
Try this: <code> &lt;ul class="list-ensemble"&gt; &lt;?php query_posts('post_type=person&amp;post_status=publish&amp;meta_key=last_name&amp;orderby=meta_value&amp;order=ASC'); $current_letter = ''; if ( have_posts() ) while ( have_posts() ) : the_post(); $last_name = get_post_meta( $post-&gt;ID, 'last_name', true ); $letter = strtolower( substr( $last_name, 0, 1 ) ); if ( $letter != $current_letter ) { $current_letter = $letter; ?&gt; &lt;li class="letter"&gt; &lt;img src="&lt;?php echo $letter; ?&gt;.jpg" alt="&lt;?php echo $letter; ?&gt;" title="&lt;?php echo $letter; ?&gt;"&gt; &lt;/li&gt; &lt;?php } ?&gt; &lt;li data-id="&lt;?php the_ID(); ?&gt;"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" class="ensemble-single-link"&gt; &lt;?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thumbnail' ); } ?&gt; &lt;/a&gt; &lt;/li&gt; &lt;?php endwhile; // end of the loop. ?&gt; &lt;/ul&gt; </code> For each post in the loop, it retrieves the <code> last_name </code> postmeta field (this won't add any queries to the page because WordPress caches the postmeta), then checks the first letter of it. If it's a new letter, it outputs a list element with an image named after the letter (e.g. <code> f.jpg </code> ).
Sort posts alphabetically by custom field value, insert divider between different letters
wordpress
i am serching a WP function that controls is there any child category/ies of current category (in category.php outside of the loop) and if there is, just add link list for that category/ies to page, otherwise (there is no child category for current) list all post(s) in this category. Thanks in advance...
You can get the current posts category outside the loop by using the get_the_category function. http://codex.wordpress.org/Function_Reference/get_the_category When you have the actual category ( however you got it) you can use get_categories, specifically the 'child_of' parameter and pass it the parent cat ID. http://codex.wordpress.org/Function_Reference/get_categories Also have a look at wp_list_catagories, http://codex.wordpress.org/Template_Tags/wp_list_categories#Display_or_Hide_the_List_Heading where you can do something simple like the following to grab the children. <code> &lt;?php wp_list_categories('orderby=id&amp;show_count=1&amp;use_desc_for_title=0&amp;child_of=8'); ?&gt; </code> You would probably do an "if" statement to get the children if they exist and if not just show the category.
Check child/parent categories if exists
wordpress
I have a custom meta box attached to a post type that displays ways for customers to submit new ideas. Customers are supposed to summarize their idea in 30 characters or less, which seems like a good use for post_excerpt. I'm not great with php (still learning) so any help with getting the echo statement right would be appreciated. Below is my custom meta box as it stands. For simplicity I have stripped away everything else. The post excerpt will display in the meta box but any edits will not save there. What am I doing wrong? <code> function idea_information() { global $post; // Noncename needed to verify where the data originated echo '&lt;input type="hidden" name="ideameta_noncename" id="ideameta_noncename" value="' . wp_create_nonce( plugin_basename(__FILE__) ) . '" /&gt;'; // Get the location data if its already been entered $quicknote = get_post_meta($post-&gt;ID, '_ideas_quicknote', true); // Echo out the fields echo '&lt;h3&gt;Basics&lt;/h3&gt; &lt;input type="text" name="excerpt" id="excerpt" value="' . $post-&gt;post_excerpt . '"/&gt;'; } // Save the Metabox Data function whiteout_save_idea_meta($post_id, $post) { // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( $_POST['ideameta_noncename'], plugin_basename(__FILE__) )) { return $post-&gt;ID; } // Is the user allowed to edit the post or page? if ( !current_user_can( 'edit_post', $post-&gt;ID )) return $post-&gt;ID; // OK, we're authenticated: we need to find and save the data // We'll put it into an array to make it easier to loop though. $station_meta['_ideas_quicknote'] = $_POST['_ideas_quicknote']; // Add values of $station_meta as custom fields foreach ($station_meta as $key =&gt; $value) { // Cycle through the $station_meta array! if( $post-&gt;post_type == 'revision' ) return; // Don't store custom data twice $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely) if(get_post_meta($post-&gt;ID, $key, FALSE)) { // If the custom field already has a value update_post_meta($post-&gt;ID, $key, $value); } else { // If the custom field doesn't have a value add_post_meta($post-&gt;ID, $key, $value); } if(!$value) delete_post_meta($post-&gt;ID, $key); // Delete if blank } } add_action('save_post', 'whiteout_save_idea_meta', 1, 2); // save the custom fields </code> Related posts: stackexchange-url ("Replace the Post Excerpt Meta Box with a Field in My Custom Meta Box")
The only custom form field that you seem to be printing out is a text input named "excerpt". In your processor script you are checking for a $_POST var named "_ideas_quicknote". Since it is not actually sent in the POST request, your processor will never see it. Please try the following: <code> &lt;?php print "\n" . '&lt;h3&gt;Basics&lt;/h3&gt;'; print "\n" . '&lt;input type="text" name="_ideas_quicknote" id="myplugin_ideas_quicknote" value="' . esc_attr( $quicknote ) . '"/&gt;'; </code>
Post excerpt in custom meta box... help with proper php format
wordpress
I've found this to display the current name of the file used in template: <code> function get_template_name () { foreach ( debug_backtrace() as $called_file ) { foreach ( $called_file as $index ) { if ( !is_array($index[0]) AND strstr($index[0],'/themes/') AND !strstr($index[0],'footer.php') ) { $template_file = $index[0] ; } } } $template_contents = file_get_contents($template_file) ; preg_match_all("Template Name:(.*)\n)siU",$template_contents,$template_name); $template_name = trim($template_name[1][0]); if ( !$template_name ) { $template_name = '(default)' ; } $template_file = array_pop(explode('/themes/', basename($template_file))); return $template_file . ' &gt; '. $template_name ; } </code> source: http://wordpress.org/support/topic/get-name-of-page-template-on-a-page It works quite well, except that in backend, in the template select box, I get this ugly extra entry: http://cl.ly/361q221Q0n0f1g473R3l Anybody has idea how to fix it? I don't even know why this function is called in backend (is there a conditional function likie <code> is_frontend() </code> - maybe this would solve the problem).
Between native WP functions like get_template_part() and PHP's native includes the most reliable way to see theme's files used is to fetch list of all included files and filter out whatever doesn't belong to theme (or themes when parent and child combination is used): <code> $included_files = get_included_files(); $stylesheet_dir = str_replace( '\', '/', get_stylesheet_directory() ); $template_dir = str_replace( '\', '/', get_template_directory() ); foreach ( $included_files as $key =&gt; $path ) { $path = str_replace( '\', '/', $path ); if ( false === strpos( $path, $stylesheet_dir ) &amp;&amp; false === strpos( $path, $template_dir ) ) unset( $included_files[$key] ); } var_dump( $included_files ); </code>
get name of the current template file
wordpress
I'd like to migrate some quite huge Wordpress-Blogs into one Multisite Installation. The Export-Wizard and the Import Wizard are bound to PHP-Limits (Memory, Execution-Time) and so the Export and Import often fails. There must be a way to do it by hand (only using MySQL and or the command line).
http://bavatuesdays.com/importing-a-single-wp-blog-to-a-wpmu-installation/ http://sillybean.net/wordpress/migrating-single-wordpress-installations-into-multisite-networks/
How to migrate Wordpress Blogs into Multisite without using the GUI-Import/Export Feature
wordpress
There's an action hook triggered in <code> admin.php </code> called <code> 'admin_action_'.$_REQUEST['action'] </code> . Unfortunately, it's a bit useless for plugins as it's triggered at the very end of admin.php, after everything's loaded on the page (even the footer). Does anyone know why it's there, why in that silly position and if anything is using it internally?
Via the "Annotate" function the the Trac, you can see that this was added three years ago , after the request for a generic POST handler that plugins can use . Google code search tells me that at least Akismet uses this hook , and it appeared there at the time it was introduced in core . It works by calling <code> admin.php </code> directly (and not the plugin page). From there it can just do a redirect at the end . The trick is thus to call <code> admin.php?action=your_action </code> , other URLs are not guaranteed to work. Many (but not all) admin pages include <code> admin.php </code> , as a sort of initialization. In this case your action would be fired before any output is sent, because the admin page includes <code> admin-header.php </code> after <code> admin.php </code> . This won't work on every admin page: not all of them include <code> admin.php </code> , and others have checks for "rogue" <code> action </code> query variables, and give you a "Are you sure you want to do that?" warning ( due to missing nonces? ). For a plugin page <code> admin.php </code> does everything : it displays the header ( unless the <code> noheader </code> query variable is in the URL ), calls your page, and displays the footer (unless you called <code> exit() </code> in your code!). <code> admin.php </code> then calls <code> exit() </code> itself, so the <code> admin_action_ </code> hook is not even called there.
What is the 'admin_action_' . $_REQUEST['action'] hook used for?
wordpress
Is there a way I can display all categories in the categories widget that comes with wordpress. I do not want to have to edit the core files and I want to stay away from rewriting the widget, but if need be I will. Is there anyway to hook into the widget just to get this functionality.
Not sure what you mean by 'display all categories', i thought it does that by default? Anyways...you can hook into it, using the following filter hooks: <code> widget_categories_args </code> <code> widget_categories_dropdown_args </code> Both hooks pass the query args to get the categories as an array. The default is <code> array('orderby' =&gt; 'name', 'show_count' =&gt; $c, 'hierarchical' =&gt; $h) </code> , wherein <code> $c </code> and <code> $h </code> are booleans and represent if the user selected 'Show post counts' and 'Show hierarchy' in the widget's options, respectively. The dropdown version gets another value: <code> $cat_args['show_option_none'] = __('Select Category'); </code> , setting the label for the 'none selected' state. You'll can hook the same callback to both filters, so that the result is the same no matter if <code> Show as dropdown </code> is selected or not. BTW: The widgets that come with WP out of the box are defined in <code> wp-includes/default-widgets.php </code> , the code in there is quite readable.
Categories widget show empty?
wordpress
I would like to know if it's possible to create a gallery like that one using WordPress: http://jfdelsalle.com/naaman.swf Is there any plugin close to that?
Of course it's possible. Galleria is a jQuery plugin that is similar, but better (fancy slide transition effects and more). You could include it yourself (see their documentation) or if you prefer WordPress plugins look at Photo Gallery which seems like it's based on galleria (haven't tried it). Another really popular gallery plugin is the NEXTGen Gallery . I'm not sure if it supports the slideshow functionality seen in your link out of the box, though. I guess some coding is required for that.
JQuery Wordpress gallery
wordpress
hey guys, i really need your help. Whenever I use a gallery in wordpress and set it's columns to just 1 Wordpress automatically adds <code> &lt;br style="clear: both"/&gt; </code> after every <code> &lt;dl class="gallery-item"&gt; </code> . I really need to prevent this behaviour and therefore I'd like to add a filter to my functions.php The following to examples don't work. <code> add_filter( 'post_gallery', 'remove_br_gallery', 9); function remove_br_gallery($output) { return preg_replace('#\&lt;br*.?\&gt;#is', '', $output); } add_filter( 'the_content', 'remove_br_gallery', 9); function remove_br_gallery($output) { return preg_replace('#\&lt;br*.?\&gt;#is', '', $output); } </code> Neither does this: <code> return str_replace('&lt;br style="clear: both"&gt;', '', $output); </code> Any idea how I could solve that? I just don't want to have any <code> &lt;br style="clear: both"/&gt; </code> inside of my galleries.
EDIT: you must call your filter after the shortcode is processed, giving it priority > 10, and you must match on a multiline expression. Try this work with my installation and using the standard gallery shortag: <code> add_filter( 'the_content', 'remove_br_gallery', 11, 2); function remove_br_gallery($output) { return preg_replace('/&lt;br style=(.*)&gt;/mi','',$output); } </code>
add_filter to post-gallery and remove all 's?
wordpress
I have just made a big mistake today using a plugin to convert my 1000+ price custom fields into child categories under Price. I didn't know the custom fields will be deleted after the conversion. The prices are still attach to their respective posts and I'll really appreciate it if somebody can help me with sql query to copy the values back to the price custom field. this is my function.php including your code <code> &lt;?php //get all categories ID's in to array $args = array( 'child_of' =&gt;3678); $categories = get_categories( $args ); $cat_array = array(); foreach ($categories as $category) { $cat_array[] = $category-&gt;term_id; } $Query_args = array( 'category__in' =&gt;$cat_array ); $new_query = new WP_Query(); $new_query-&gt;query($Query_args); if ($new_query-&gt;have_posts()){ while ($new_query-&gt;have_posts()){ $new_query-&gt;the_post(); foreach((get_the_category()) as $category) { if (in_array($category-&gt;cat_ID,$cat_array){ update_post_meta($post_id, 'price', $category-&gt;cat_name); } } } } /************************************************************* * Do not modify unless you know what you're doing, SERIOUSLY! *************************************************************/ /* Admin framework version 2.0 by Zeljan Topic */ // Theme variables require_once (TEMPLATEPATH . '/library/functions/theme_variables.php'); //** ADMINISTRATION FILES **// // Theme admin functions require_once ($functions_path . 'admin_functions.php'); // Theme admin options require_once ($functions_path . 'admin_options.php'); // Theme admin Settings require_once ($functions_path . 'admin_settings.php'); //** FRONT-END FILES **// // Widgets require_once ($functions_path . 'widgets_functions.php'); // Comments require_once ($functions_path . 'comments_functions.php'); // Yoast's plugins require_once ($functions_path . 'yoast-breadcrumbs.php'); require_once ($functions_path . 'yoast-posts.php'); //require_once ($functions_path . 'yoast-canonical.php'); require_once ($functions_path . 'yoast-breadcrumbs.php'); /////////shopping cart new function files require($functions_path . "general_functions.php"); require($functions_path . "cart.php"); require($functions_path . "product.php"); require($functions_path . "custom.php"); require(TEMPLATEPATH . "/product_menu.php"); // Custom require_once ($functions_path . 'custom_functions.php'); ///message - language file require(TEMPLATEPATH . "/message.php"); if('themes.php' == basename($_SERVER['SCRIPT_FILENAME']) &amp;&amp; $_REQUEST['page']=='') { if($_REQUEST['dummy']=='del') { delete_dummy_data(); echo THEME_DUMMY_DELETE_MESSAGE; } $post_counts = $wpdb-&gt;get_var("select count(post_id) from $wpdb-&gt;postmeta where meta_key='pt_dummy_content'"); if(($_REQUEST['template']=='' &amp;&amp; $post_counts&gt;0 &amp;&amp; $_REQUEST['page']=='') || $_REQUEST['activated']=='true') { echo THEME_ACTIVE_MESSAGE; } if($_REQUEST['activated']) { require_once (TEMPLATEPATH . '/auto_install.php'); } } function delete_dummy_data() { global $wpdb; $productArray = array(); $pids_sql = "select p.ID from $wpdb-&gt;posts p join $wpdb-&gt;postmeta pm on pm.post_id=p.ID where meta_key='pt_dummy_content' and meta_value=1"; $pids_info = $wpdb-&gt;get_results($pids_sql); foreach($pids_info as $pids_info_obj) { wp_delete_post($pids_info_obj-&gt;ID); } } ?&gt; </code>
paste this code in you theme's function.php file <code> //get all categorie ID's in to array $args = array( 'child_of' =&gt; 3678); // Parent category ID $categories = get_categories( $args ); $cat_array = array(); foreach ($categories as $category) { $cat_array[] = $category-&gt;term_id; } $Query_args = array( 'category__in' =&gt; $cat_array, 'post_type' =&gt; 'YOUR_POST_TYPE_NAME' ); $new_query = new WP_Query(); $new_query-&gt;query($Query_args); if ($new_query-&gt;have_posts()){ while ($new_query-&gt;have_posts()){ $new_query-&gt;the_post(); foreach((get_the_category()) as $category) { if (in_array($category-&gt;cat_ID,$cat_array)){ update_post_meta($post_id, 'price', $category-&gt;cat_name); } } } } </code> replace "Parent category ID" with price category ID and then save that file after that remove this code and save again.
Copy price categories to custom field
wordpress
I have custom post type (entertainment) and I set up a taxonomy (review) as hierarchal so there are check boxes under the taxonomy. Most of the post in the entertainment are just post but we also have reviews. What I was hoping is that if it's a review then you can just check what type of review in the review taxonomy box, an example is "movie". I am trying to display the latest review using <code> query_posts( array('tax_query' =&gt; array(array('taxonomy' =&gt; 'review','field' =&gt; 'slug','term' =&gt; 'movie')), 'posts_per_page'=&gt;'1', 'caller_get_posts'=&gt;'1') ); </code> But it's showing the latest post and not the one selected as movie. I'm on WP 3.1
You can do a straight query for the taxonomy term: <code> query_posts( array( 'review' =&gt; 'movie' ) ); </code> To query multiple terms you can use tax_query: <code> 'tax_query' =&gt; array( 'taxonomy' =&gt; 'review', 'field' =&gt; 'slug', 'terms' =&gt; array( 'movie', 'term', 'term' ), ), </code>
Display latest post of taxonomy
wordpress
Example I want combine shortcode for first paragraph and dropcap. <code> function st_dropcap( $atts, $content = null ) { return '&lt;span class="dropcap"&gt;'.$content.'&lt;/span&gt;'; } add_shortcode('dropcap', 'st_dropcap'); function st_paragraph( $atts, $content = null ) { return '&lt;p class="first-paragraph"&gt;'.$content.'&lt;/p&gt;'; } add_shortcode('paragraph', 'st_paragraph'); </code> On post I tried something like this <code> [paragraph][dropcap]W[/dropcap]elcome to my blog[/paragraph] </code> Only paragraph is working. How do I combine this code? Let me know
Change <code> st_paragraph() </code> to this: <code> function st_paragraph( $atts, $content = null ) { return '&lt;p class="first-paragraph"&gt;'.do_shortcode($content).'&lt;/p&gt;'; } </code> See Codex documentation .
How do I combine my shortcodes?
wordpress
I am now developing a wordpress site that will be something like a directory. People will be able to submit walkthroughs, advanced reviews, as well as cheat codes for games. We were going to make a different form for each page, but now we've decided that one form with a drop down will be just fine. There doesn't seem to be a good plug in out there, that I can find, which accommodates the fact that each submission needs to be pushed through as a "pending post" but also to a certain post type. For example, the form that we'll use will be set up like this: <code> Game name: &lt;post title&gt; Platform: &lt;Taxonomy&gt; Category: &lt;Category&gt; (role playing, FPS, adventure, etc..) This is a: () Review () Tutorial () Cheat list &lt;this is the post type&gt; Content: &lt;post body&gt; Tags: &lt;tags&gt; [Submit] </code> Upon submission, I need for the review, cheat, or tutorial to be set as a pending post, in the post type chosen from the radio boxes. I'm currently using WP User Front End, but I could probably use any post from front-end form that is suggested for easiest modification. Adding the new fields to the form is easy, making them do stuff is hard! I'd appreciate any help I can get with this, our website sort of revolves around these feature.
It looks like Gravity Forms can do this. I just did a quick search on the support forums and found this, an answer to someone asking almost exactly the same question as you: Gravity Forms can be used to create custom post types as well as custom taxonomies, however it doesn't do so out of the box. It requires the use of available hooks to tell Gravity Forms to use a custom post type or custom taxonomy instead of the default. By default it uses standard WordPress Posts, Categories and Tags. So yes it is possible, but it does take some custom code. When you are ready to implement this you can search the forums for code examples as many people have done this, or you can post a new post describing what you are trying to do and request some assistance and we can assist you with basic code snippets to get you started. We do plan on creating an Add-On in the future that will make it much easier to create custom post types and use custom taxonomies.
Post from front-end with post types, categories and taxonomies
wordpress
My wordpress theme creates thumbnails of media files that I upload into my posts. These thumbnails are not accessible inside the media gallery, they exist only in the media upload directory. I want to access these thumbnail files in my media gallery. How do I import files in my upload directory into media gallery?
For a one-off batch operation, you can use this plugin: http://wordpress.org/extend/plugins/add-from-server/ But first you should figure out why they don't show up in the first place. Maybe complain to the theme developer.
How to bring files from the upload directory to the media gallery?
wordpress
I'm constantly running into the same annoyance, so i thought i'd see if there's any ideas or experience out there... I've created a plugin that uses it's own admin page. It has to. Now that i sorted out the WP_List_Table() stuff, i must say it's great...but.... Custom plugin pages always load as <code> admin.php?page=... </code> unless i want to load them from the plugin directory directly, which i don't. Now if i do an 'action' from that page, i need to process that somehow and then redirect back to the page without the action parameter. No matter if i do a GET or POST, really. On all it's internal pages WP does this on the same page, it checks if there's an action, if so processes it and then redirects to itself without the action. This is possible, because on these pages the <code> admin-header </code> hasn't been loaded, yet. If you try doing it on your own page, though, half the admin interface has already been sent to the browser, so a redirect isn't possible anymore. Clearly, the solution is to POST/GET directly to another page, load the WP framework on that, do the processing and then redirect back to the original page...but...that's a bit annoying, because...my original page is loaded via a callback, so it runs within a method of my class. That's beautiful. If i load a separate page, i have to manually include <code> wp-load.php </code> and am outside of my class, which is annoying, and in my particular case bugs me especially, because i'm only instanciating my plugin class anonymously so that no-one can access it from the outside. So after this long story...did anyone come up with a good solution to load another page via a callback without having the whole admin interface already setup around it? (I know of a workaround...i can hook a function into <code> load-.... </code> that checks for the action parameter and does the processing and redirect. But i'm wondering if there's a better way.) Thanks.
As a rule of thumb, you should use a POST request for most actions, to make sure they are not executed by accident. But it is also a good practice to redirect to a normal page after a POST request, to prevent duplicate execution when the user refreshes the page. So the flow is like this: Your plugin page with a POST form, which submits to A page that handles the request, which redirects to Your plugin page, which shows the result of the action The middle page doesn't have to be your plugin page. This means that you can use the "generic POST handler" that was included three years ago, the <code> 'admin_action_' . $_REQUEST['action'] </code> hook in <code> admin.php </code> . An example user is the Akismet plugin. If you want to use it reliably, admin.php </code> directly , not to another page that happens to include <code> admin.php </code> . Here is a very basic example of how to use it: <code> add_action( 'admin_action_wpse10500', 'wpse10500_admin_action' ); function wpse10500_admin_action() { // Do your stuff here wp_redirect( $_SERVER['HTTP_REFERER'] ); exit(); } add_action( 'admin_menu', 'wpse10500_admin_menu' ); function wpse10500_admin_menu() { add_management_page( 'WPSE 10500 Test page', 'WPSE 10500 Test page', 'administrator', 'wpse10500', 'wpse10500_do_page' ); } function wpse10500_do_page() { ?&gt; &lt;form method="POST" action="&lt;?php echo admin_url( 'admin.php' ); ?&gt;"&gt; &lt;input type="hidden" name="action" value="wpse10500" /&gt; &lt;input type="submit" value="Do it!" /&gt; &lt;/form&gt; &lt;?php } </code>
How do i best handle custom plugin page actions?
wordpress
This is similar to another question I asked, but I can't recognize how this query string works. I have a custom field called "category_order" and I would like to sort my category page by this order (and not the date). Here is my code: <code> &lt;?php wp_reset_query(); ?&gt; &lt;div id="content"&gt; &lt;div id="postFuncs"&gt; &lt;div id="funcStyler"&gt;&lt;a href="#" class="switch_thumb"&gt;&lt;/a&gt;&lt;/div&gt; &lt;?php if (is_category()) { $cat_ID = get_query_var('cat'); ?&gt; &lt;?php echo '&lt;h2&gt;'; wpzoom_breadcrumbs(); echo'&lt;/h2&gt;'; ?&gt;&lt;?php } elseif (!is_category() &amp;&amp; !is_home()) { ?&gt; &lt;?php echo '&lt;h2&gt;'; wpzoom_breadcrumbs(); echo'&lt;/h2&gt;'; ?&gt; &lt;?php } else { ?&gt; &lt;h2&gt;Recent Videos&lt;/h2&gt; &lt;?php } ?&gt; &lt;/div&gt;&lt;!-- end #postFuncs --&gt; &lt;div id="archive"&gt; &lt;?php if (have_posts()) : ?&gt; &lt;ul class="posts posts-3 grid"&gt; &lt;?php $i = 0; while (have_posts()) : the_post(); $i++; ?&gt; </code>
I added the <code> query_posts </code> so we can tell Wordpress of a modified query to run. <code> $query_string </code> will let us add onto the current parameters. <code> orderby, meta_key, order </code> let us define the query by telling it how to sort the results More information on ordering by parameters <code> &lt;?php wp_reset_query(); ?&gt; &lt;div id="content"&gt; &lt;div id="postFuncs"&gt; &lt;div id="funcStyler"&gt;&lt;a href="#" class="switch_thumb"&gt;&lt;/a&gt;&lt;/div&gt; &lt;?php if (is_category()) { $cat_ID = get_query_var('cat'); ?&gt; &lt;h2&gt;&lt;?php wpzoom_breadcrumbs(); ?&gt;&lt;/h2&gt; &lt;?php } elseif (!is_category() &amp;&amp; !is_home()) { ?&gt; &lt;h2&gt;&lt;?php wpzoom_breadcrumbs(); ?&gt;&lt;/h2&gt; &lt;?php } else { ?&gt; &lt;h2&gt;Recent Videos&lt;/h2&gt; &lt;?php } ?&gt; &lt;/div&gt;&lt;!-- end #postFuncs --&gt; &lt;div id="archive"&gt; &lt;?php global $query_string; query_posts( $query_string . '&amp;orderby=meta_value_num&amp;meta_key=your_custom_field"&amp;order=ASC'); if (have_posts()) : ?&gt; &lt;ul class="posts posts-3 grid"&gt; &lt;?php $i = 0; while (have_posts()) : the_post(); $i++; ?&gt; </code>
Sort category page with custom field
wordpress
I've seen the tutorials on how to grab the first image and display it in a post, and those on grabbing the post_thumbnail and using that in the RSS feed, but does anybody know how to grab the first image attached to a post and use that in the RSS feed? Thanks!
I ended up using a plugin called "RSS Custom Field Images" and it worked out of the box for me. I could even edit it to change the size of the image to something more manageable for me.
How to grab first image attached to post and display in RSS feed?
wordpress
I'm developing a plugin made on the original calendar. My wordpress is based on real events and I want to keep trace of theme on the calendar. So I added a custom field in the post which is the end of the events (or the last day for subriscribe) with the value of a date of course (like 25/02/2010). Now I want to display on the calendar all the events that ends on the days instead of the posts create in each days. How to get the meta data value of the post in this query? <code> // Get days with posts $dayswithposts = $wpdb-&gt;get_results("SELECT DISTINCT DAYOFMONTH(post_date) FROM $wpdb-&gt;posts WHERE MONTH(post_date) = '$thismonth' AND YEAR(post_date) = '$thisyear' AND post_type = 'post' AND post_status = 'publish' AND post_date &lt; '" . current_time('mysql') . ''', ARRAY_N); </code> It have to select all the post with my custom meta value. Hope I'm not doing this for nothing, I googled and no plugin with this function came out.
I think you can do a left join : <code> left join $wpdb-&gt;postmeta my_field_meta on (p.ID = my_field_meta.post_id and my_field_meta.meta_key = 'subscribe') </code> Where "subscribe" it's the name of your custom field. So your code could be: <code> $dayswithposts = $wpdb-&gt;get_results("SELECT DISTINCT DAYOFMONTH(p.post_date) FROM $wpdb-&gt;posts as p LEFT JOIN $wpdb-&gt;postmeta my_field_meta on (p.ID = my_field_meta.post_id and my_field_meta.meta_key = 'subscribe') WHERE MONTH(p.post_date) = '$thismonth' AND YEAR(p.post_date) = '$thisyear' AND p.post_type = 'post' AND p.post_status = 'publish' AND p.post_date &lt; '" . current_time('mysql') . ''', ARRAY_N); </code>
get all posts with certain meta data
wordpress
Let say my theme host on my server. User download my theme and use it. Now I want notify @ alert for new version of my theme. Example to show "New version has been release. Please download at ..." How to do that?
see: http://clark-technet.com/2010/12/wordpress-self-hosted-plugin-update-api Basically the idea is to hook your update checking function to the <code> pre_set_site_transient_update_themes </code> filter. The version array key you return from this function will be compared by WP to the current theme version from style.css.... Use the <code> admin_notices </code> action to make your alert message more noticeable
How to make alert for new version on theme options?
wordpress
There are so many free, freemium and premium Themes out there. How can I be sure that a Theme I download doesn't have malware in the code? Is there an (relatively) easy way to check for malicious code without going through every line of code?
You should try using the theme check plugin at http://wordpress.org/extend/plugins/theme-check/
How can I check for malware in a Theme?
wordpress
Dreamweaver CS5 is very useful to design or modify a Wordpress theme. It inspects CSS elements in Live view (after seting up a test server), but its unable to trace original wordpress code responsible for generating front-end HTML. So, I'm looking for a smart dev tool which could trace internal PHP code responsible for generating selected front-end HTML.
Any decent IDE for PHP comes with search capabilities. It is usually rather easy to find code responsible if it uses specific ids and/or class names. Personally I use NetBeans for PHP, also see stackexchange-url ("Software for WordPress Theme and Plugin Development?") question. A tons of good tools mentioned there.
Is there any tool to find lines of codes responsible to generate front-end HTML elements?
wordpress
I am using both wp_update_user() and update_user_meta() and I want to be able to check for an error, and if one occurs, output it to the user. Is this possible using something like $result = wp_update_user()? I don't want an integer though I want to read the text of the error.
Not really. Deep down such functions are essentially writes to database. So either database write fails (which doesn't produce meaningful message to return) or data is somehow wrong and function just returns <code> false </code> to escape. Your best bet is probably to control data user inputs, not result of WP trying to process that data. PS worth mentioning that for debug <code> WP_DEBUG </code> and <code> wpdb </code> error echoing rock, but it's not exactly what you are asking for.
Is it possible to read a result if wp_update_user or update_user_meta fails?
wordpress
I have a site with eight custom post types. Each is registered with <code> 'menu_position' =&gt; 5 </code> (below the Post menu). A side effect of having more than four CPTs is that the Media menu now appears in the middle of the list of CPTs (see image). My solution is to duplicate the Media menu item in a lower position, then unset the original Media menu item: <code> add_action( 'admin_head', 'change_menu_items' ); function change_menu_items() { global $menu; $menu[14] = $menu[10]; unset( $menu[10] ); } </code> My question is: is this likely to cause any unforeseen side effects? I haven't come across any yet, but just wanted to make sure. Thanks!
this might work: <code> add_filter('custom_menu_order', 'my_custom_menu_order'); add_filter('menu_order', 'my_custom_menu_order'); function my_custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'index.php', // the dashboard link 'edit.php?post_type=custom_post_type', 'edit.php?post_type=page', 'edit.php' // posts // add anything else you want, just get the url ); } </code>
Is it OK to move admin menu items?
wordpress
I'm looking for the best way to inject CSS into WordPress' Admin CP. Currently, I'm using the <code> admin_head </code> action hook and in this hook, I'm using <code> dirname( __FILE__ ) </code> to retrieve the directory for the stylesheets. However, <code> dirname() </code> does retrieve the server's path. Is this the recommended way or is there some sort of WordPress function to get a URI path rather than a directory path? <code> public function admin_head() { // Let's include the Control Panel CSS $url = dirname( __FILE__ ) . '/css/cpanel.css'; $ie = dirname( __FILE__ ) . '/css/cpanel-ie.css'; // Inject our cPanel styelsheet and add a conditionaly for Internet Explorer // (fixes bugs on my home browser) $head = &lt;&lt;&lt;HEAD &lt;link rel="stylesheet" href="{$url}" type="text/css" media="screen" /&gt; &lt;!--[if IE]&gt; &lt;link rel="stylesheet" type="text/css" href="{$ie}" media="screen" /&gt; &lt;![endif]--&gt; HEAD; echo $head; foreach( self::$classes as $class =&gt; $obj ) { if ( method_exists( $obj, 'admin_head' ) ) { $obj-&gt;admin_head(); } } } </code> -Zack
See <code> plugins_url() </code> . It's perfect and engineered to link to files in plugin folders. PS also <code> wp_enqueue_style() </code> might make sense in the mix.
Best way to inject css into admin_head in plugins?
wordpress
A lot of questions are about plugins and themes, that you don't necessarily have installed. Downloading zip archive, unpacking and opening in editor seems like a too much hassle. If only there was a way to just browse source of WordPress and all of plugins and themes int its repository...
Good news and more good news! First - all of the code related to WordPress itself and its repositories resides in version control system ( Subversion ). Among other things that makes publicly available sites with all code in plain sight: http://core.svn.wordpress.org/ http://themes.svn.wordpress.org/ http://plugins.svn.wordpress.org/ One not so obvious result of that - if you can see it, so can our overlord Google. Basically you can google through that code quite successfully by adding modifier like <code> site:http://core.svn.wordpress.org/ </code> to your query. But that is not all. WordPress project also uses Trac . That is actually piece of software, not just mythical place for WP demigods to hang out. Among other things trac has browser feature that interfaces with SVN and provides prettified, ajaxified and in other ways glorious human-friendly way to browse through code: http://core.trac.wordpress.org/browser http://plugins.trac.wordpress.org/browser http://themes.trac.wordpress.org/browser Note that it can take a long time to open root of browser for plugins and themes, because there are tons of either. It is usually faster to type in name of specific plugin/theme at end of URL (it will be same as in repository), for example http://themes.trac.wordpress.org/browser/hybrid Also note that trac browser gives nice way to link to specific lines of code for reference, with number of line for an anchor http://themes.trac.wordpress.org/browser/hybrid/0.8/index.php#L13 In addition to wordpress.org theme repository, free themes for wordpress.com are available as public SVN repository at: https://wpcom-themes.svn.automattic.com/ While development of WordPress is happening via SVN so far, GitHub mirror was created (first maintained by Mark Jaquith and later promoted to official status): https://github.com/WordPress/WordPress There is no official Mercurial mirror so far, but unofficial one is maintained by me at Bitbucket: https://bitbucket.org/Rarst/wordpress
How to look at code in WordPress repositories without downloading?
wordpress
I have created a site and would like to create another version of the same site using the same exact database (db location, users, everything). The two sites would share one database. I already have one site created and wanted to know how feasible it is to do, and instructions on how to do it. Currently, the site up now is for consumers and the other version will be for corporate clients. Please give me some advice on how to do this. The site is: www.savingsulove.com Thanks a lot for the help.
Hi @user1893: There are a couple of ways you can achieve what you asked for but the latter is what I'd recommend: Set up a copy of the site in a different directory and using your web host's control panel map the different domains to the appropriate directories. Use the same <code> DB_NAME </code> / <code> DB_USER </code> / <code> DB_PASSWORD </code> / <code> DB_HOST </code> in the <code> /wp-config.php </code> file for each of your sites but include different defines for <code> WP_HOME </code> and <code> WP_SITEURL </code> in each file. You might run into a few glitches but I think you can work through them by asking more questions here on WordPress Answers. Use one site with two different themes , add logic in <code> /wp-config.php </code> to recognize the different domains, and various hooks you might need to get things to behave as you want especially including one to load the right theme. What follows is (some of?) the code you'll need for option #2. Using One Site with Two Different Themes: This code goes in your <code> /wp-config.php </code> file anywhere before <code> require_once(ABSPATH . 'wp-settings.php'); </code> : <code> $this_domain = $_SERVER['SERVER_NAME']; switch ($this_domain) { case: 'www.savingsulove.com': case: 'www.savings4biz.com': // I made up this domain to enable this example define('WP_HOME',"http://{$this_domain}"); define('WP_SITEURL',"http://{$this_domain}"); default: echo 'Invalid domain'; die(); } </code> Then to switch the theme based on the domain use the <code> template </code> hook with the logic below. Probably the best place to put this code would be in a "Must Use" plugin; i.e. put the following into <code> /wp-content/mu-plugins/savingsulove-theme-switcher.php </code> . This code assumes you've got two themes in the respective subdirectories <code> /wp-content/themes/savingsulove/ </code> and <code> /wp-content/themes/savings4biz/ </code> . <code> /* File Name: savingsulove-theme-switcher.php Plugin Name: Switch the Theme Based on Domain */ add_action('template','savingsulove_template'); function savingsulove_template($template) { if ($_SERVER['SERVER_NAME']=='www.savingsulove.com') $template = 'savingsulove'; else $template = 'savings4biz'; return $template; } </code> Beyond that, you can add any other shared code as a "Must Use" plugin like above (or just add more code to the <code> savingsulove-theme-switcher.php </code> file) where you just inspect the value in <code> $_SERVER['SERVER_NAME'] </code> to decide what to do. If you need help with any additional aspects that might occur, <a href="stackexchange-url just ask another question here (as opposed to adding follow up questions in the comments on this page after this question has been answered.) P.S. There are more maintenance-free ways I could have written the above code but then it would have been more obscure and harder for a reader new to the techniques to follow what I was doing.
How to create another version of my site based on the same database
wordpress
I just moved a site from one domain to another and now category links are all 404. I have flushed the rewrite rules, recreated the .htaccess file but still it throws up 404. Weird thing is that if I delete <code> .htaccess </code> file, then the posts are still accessible by <code> domain.com/postname/ </code> and when I save permalinks, then it is created there. So can it be the case it is using some other .htaccess file? Possibly some fallback that I am not aware of? Re-Edit: Tag pages don't work fine . Its all weird. Tags generally give 404, one of them opened a non 404 page but not what it should be (i.e. posts listing under that tag). And a category redirects itself to one of the posts. This all led me to conclude that tags were working but they are not. Also everything works, when I turn off the permalinks. I am using a custom slug for category "cat" and not the default "category" but reverting to the default doesn't solve anything. Any clues? Edit: I saw Ipstenu's sticky on WP forums and found that Advanced Permalinks are known to have a problem with WP 3.1, so I disabled it and recreated by permalinks but still no joy. What did I miss? So far, I have tried recreating permalinks, flushing rewrite rules by calling <code> global $wp_rewrite; $wp_rewrite-&gt;flush_rules(); </code> in <code> functions.php </code> , deleting <code> rewrite_rules </code> in <code> options table </code> &amp; even deleting <code> .htaccess </code> file. So I am clueless and would appreciate if someone can give me a clue how it can be fixed. Further Edit: If I delete the .htaccess file, the site behaves if it was there and I can browse pretty permalinks without any issue (.htaccess file is not there in the WP root) but when I resave permalinks, it is created there. So can there be some kind of fallback for .htaccess because this shouldn't be possible without rules in .htaccess? EDIT: I am still stuck at the issue. Can anyone please help me out? Final Edit: Is there anything left in the wild that I can do to troubleshoot this issue? I have lost hope on this one.
After trying everything out, nothing worked but then all of a sudden, deleting .htaccess file and re-saving permalinks did the job.
WordPress category gives 404 after moving to a different domain
wordpress
The plugin should work with un-registered users also. Its not mandatory for plugin to add rating system to posts/pages. I need thumbs up-down rating system only for comments.
i bet there are a lot but i have used Comment Rating plugin before and its very good just for that.
Is there any plugin which enables users to rate comments in thumbs up-down way?
wordpress
I used to post same shortcodes every time (shortcodes loads dynamic contents). So, I want to pack these shortcodes in a template for my posts. How can I do this?
You might want to check out... http://codex.wordpress.org/Function_Reference/do_shortcode But the gist for using shortcodes in a template is as follows... <code> // Use shortcode in a PHP file (outside the post editor). do_shortcode('[gallery]'); </code>
How to make post templates to include shortcodes only?
wordpress
Hey guys, i did a mistake on a wp site, i uploaded a wrong wp-config.php file on the server during a 3.1 update, saw the mistake, recreated a good one with the good infos, uploaded the file and didnt get back the site! Now wordpress askes me to install it! Which i dont want to, cos it's all already installed. I backuped the database and checked it online, it's all fine, with for exemple the good infos for 'home' and 'url' tables. If anyone knows what's going on (the install question) and i could get it back, it'd be more than welcome (am kinda stressed a lot now). Second question, if i do reinstall it, will it crash the existing datas in the database? EDIT: i checked the english version which is on the same database on the same server, site.com/en, it works fine.
Got it back, the <code> $table_prefix </code> line was wrong in my wp-config.php. Fiu.
WP already installed is asking to install
wordpress
I have the following code in my search results page to split up posts per category. When I go to the 2nd page of pagination, the results are exactly the same as the first. I'm assuming $paged has to be inserted but i'm not sure where. Any help would be appreciated Code: http://wordpress.pastebin.com/qWnaLxgd
In line 51: <code> query_posts("s='$s'&amp;cat=177"); </code> change to this: <code> $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("s='$s'&amp;cat=177&amp;paged=$paged"); </code>
Search results with custom loop don't update when paged
wordpress
With WP 3.1, as we all know, the admin bar is a new feature on your blog when you are logged in as an administrator, but for some reason on my theme, the admin bar is not there. In it's place is a grey bar about 30 pixels tall (matching my pages background color). What could be hiding it? If it's useful, the theme is at wphax.com
Check <code> footer.php </code> and make sure it contains <code> &lt;?php wp_footer(); ?&gt; </code> .
New Admin Bar Not Functioning
wordpress
I need to get any posts by an id list ($id_list), here is my codes <code> query_posts(array('posts_per_page'=&gt;-1, 'caller_get_posts'=&gt;1, 'post_type'=&gt;'any', 'post__in'=&gt;$id_list) ); </code> i got posts and pages by this query, but attachments don't get included, i found they are filtered by 'post_type=any' which actually doesn't include attachment. How do i get them all without have to do an extra query?
'post_type'=> 'any' should get you all types except revisions so you should get the attachments but if you don't try: <code> query_posts( array( 'posts_per_page' =&gt; -1, 'ignore_stickies' =&gt; 1, 'post_type'=&gt; array( 'post', 'page', 'attachment' ), 'post_status' =&gt; array( null ), 'post__in'=&gt; $id_list ) ); </code> Update As t31os pointed out that: Attachments don't have a publish status, which is default for the query so i added to the query_posts array <code> 'post_status' =&gt; null </code> and that should fix your query
How to get any type posts include attachments by ids?
wordpress
I'm currently working on a search function in a wp site. The plan is to have a search function on the news page which just searches posts. I'm achieving this by adding the below to my functions.php file: <code> /* search just posts */ function SearchFilter($query) { if ($query-&gt;is_search) { $query-&gt;set('post_type', 'post'); } return $query; } add_filter('pre_get_posts','SearchFilter'); </code> which works fine. BUT. I also need to create a search on a custom post type listing - for just the custom posts and also one for the entire site to live on the 404 page. Any ideas how to go about this greatly appreciated?
you can change your search filter to this: <code> function SearchFilter($query) { $post_type = $_GET['post_type']; if (!$post_type) { $post_type = 'any'; } if ($query-&gt;is_search) { $query-&gt;set('post_type', $post_type); }; return $query; } add_filter('pre_get_posts','SearchFilter'); </code> then on your news search form add : <code> &lt;input type="hidden" name="post_type" value="post" /&gt; </code> on your custom post type listing search form add <code> &lt;input type="hidden" name="post_type" value="customtypename" /&gt; </code> and on the entire site search for don't add anything an you are set.
Create multiple Search functions for posts / custom post types and everything
wordpress
I was on the latest v3.0.x series and had no issues. Once I upgraded to WP v3.1, I am having a strange issue with character encoding in permalinks. If my title was "I have $50 today" in WP 3.0.x, the month/date permalink would be <code> example.com/2010/05/i-have-50-today/ </code> However, here's what is happening in WP 3.1 <code> example.com/2010/05/i-have-%e2%80%93-50-today/ </code> I tried replicating the problem on a clean install of WordPress and was able to replicate the same issue. Can anyone confirm whether this is a bug or expected?
I solved the problem. The permalink slug under the title of a new post would not let me tweak the slug for some reason. I was able to get rid of the unwanted '-' in the permalink by heading to the posts list and clicking quick edit to edit the slug over there.
WordPress v3.1 Has Character Encoding Issue With Title/Permalink?
wordpress
I have a series of posts (using a wp-zoom theme). I would like to create a custom field called <code> order </code> and sort by that field. Here is part of my homepage code: <code> &lt;?php $z = count($wpzoom_exclude_cats_home); if ($z &gt; 0) { $x = 0; $que = ""; while ($x &lt; $z) { $que .= "-".$wpzoom_exclude_cats_home[$x]; $x++; if ($x &lt; $z) { $que .= ","; } } } query_posts( $query_string . "&amp;cat=$que" ); if (have_posts()) : ?&gt; </code>
You can use the "orderby" parameter of query_posts . You must specify your custom field and you must give it a numeric value. Short example: <code> query_posts($query_string . "&amp;cat=$que&amp;orderby=meta_value_num&amp;meta_key=your_custom_field") </code>
Sorting posts ordered by custom field value
wordpress
Is there a way (besides adding a Custom Link) to add a custom post type archive to a menu in WordPress? If it's added using a custom link (e.g. /cpt-archive-slug/), WordPress does not apply classes like <code> current-menu-item </code> to the list element, which presents challenges when styling the menu. If the custom link contains the entire URL (e.g. http://site.com/cpt-archive-slug/), those classes are added. However, that's probably not a 'best practice'.
your best opption is custom link with full url as Custom post types archives are different form taxonomy based archives (categories,tags,any custom taxonomy) and date based archives which have there own archive slug.
Adding custom post type archives to a WordPress menu
wordpress
Removing RewriteBase / from my htacess has sped up my site which is still working correctly. Is it really required and what is it for?
'RewriteBase /' is not needed. RewriteBase allows you to change your internal directory structure to something other than what a browser sees. IE: If all your files are in 'http://mydomain.com/site', but you wanted 'http://mydomain.com' to be the path browsers see, you would use a <code> RewriteBase /site </code> and apache's mod_rewrite would happily add that substitution for you. A <code> RewriteBase / </code> is not necessary.
Wordpress and Htaccess
wordpress
Can anyone recommend a flexible lightbox plugin that allows the popup lighbox to use an image and/or HTML? I want to overlay some sort of help instructions on top of my WP home page. Thanks!
any of the folowing should do just fine: Overlay FancyBox for WordPress Simple Lightbox WP Multibox TopUp Plus and my personal favorite Highslide 4 WordPress reloaded
Recommend a flexible lightbox that allows an image or HTML to be used
wordpress
How to display a list of posts from today date to future? I am actually using this code: <code> &lt;div id="news-loop"&gt; &lt;?php if (have_posts()) : ?&gt; &lt;?php query_posts('cat=4&amp;showposts=6&amp;orderby=date&amp;order=DESC&amp;post_status=future&amp;post_status=published'); while (have_posts()) : the_post(); ?&gt; &lt;p&gt;&lt;?php the_time('j F, Y') ?&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" &gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;?php endwhile; ?&gt; &lt;?php else : ?&gt; &lt;?php endif; ?&gt; </code> This is showing correctly all the posts and future posts for that category. An additional problem is: since I'm using "post_status=future&amp;post_status=published" I have to trash the old posts to avoid them being displayed. Thanks for your help!
According to query_posts you could do a filtering function like: <code> function filter_where( $where = '' ) { // where post_date &gt; today $where .= " AND post_date &gt;= '" . date('Y-m-d') . "'"; return $where; } add_filter( 'posts_where', 'filter_where' ); </code> And then your <code> query_posts </code> doesn't need to have <code> post_status </code>
Display posts starting from today date
wordpress
I'm using the Vote it up plugin. Is there a way of placing the two most voted posts at the top? (Like in Youtube)? I'm not very sure if this is hard or easy to accomplish. EDIT: Someone posted a method in the Wordpress forums here , but stackexchange-url ("Mike Schindel") said: This example is absolutely AWFUL. It may work but it's far more code than you needs and may break on a future version of WordPress. I've been playing with Wordpress for a while but Im still a PHP beginner. Is there a way of fixing that code posted in the Wordpress forums? Or a better method?
a while back i used that plugin and i needed a way to list most voted posts so after looking at the plugin's widget code and i came up with this function: <code> function top_voted($number){ $a = SortVotes(); echo '&lt;div class="voted"&gt;'; $rows = 0; //Now does not include deleted posts $i = 0; while ($rows &lt; $number)) { if ($a[0][$i][0] != '') { $postdat = get_post($a[0][$i][0]); if (!empty($postdat)) { $rows++; echo '&lt;div class="fore"&gt;'; echo '&lt;div class="votecount" style="width: 1em; color: #555555; font-weight: bold;"&gt;'.$a[1][$i][0].' &lt;/div&gt;&lt;div&gt;&lt;a href="'.$postdat-&gt;guid.'" title="'.$postdat-&gt;post_title.'"&gt;'.$postdat-&gt;post_title.'&lt;/a&gt;&lt;/div&gt;'; echo '&lt;/div&gt;'; } } if ($i &lt; count($a[0])) { $i++; } else { break; //exit the loop } } echo '&lt;/div&gt;'; } </code> Usage: <code> top_voted(5); </code>
Placing the two most voted posts at the top (in a Wordpress site that uses the Vote it up plugin)?
wordpress
I'm trying to show result for a custom field that is not empty on a custom post type but getting no results? <code> &lt;?php if (have_posts()) : $args = array( 'post_type' =&gt; 'programmes', 'meta_query' =&gt; array( 'key' =&gt; 'linktovideocatchup', 'value' =&gt; '', 'compare' =&gt; 'NOT LIKE'), //'caller_get_posts' =&gt; 1, ); ?&gt; &lt;?php query_posts( $args ); ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; `enter code here` </code>
you're missing an array within the meta_query element: <code> $args = array( 'post_type' =&gt; 'programmes', 'meta_query' =&gt; array( array( 'key' =&gt; 'linktovideocatchup', 'value' =&gt; '', 'compare' =&gt; 'NOT LIKE' ) ) ); </code> (this is required to allow for querying of multiple meta fields.) you also had an extraneous comma after the meta_query array element which can cause problems. i think you should also be able to use the operator '&lt;> ' rather than 'NOT LIKE', i believe it's more efficient. there's a good write-up on the meta_query functionality here: http://scribu.net/wordpress/advanced-metadata-queries.html
meta query not showing any results?
wordpress
I'm creating new pages under Pages > Add new. And creating my own page.php file from the ground up, what's the best way of displaying pages contents? I guess not get_template_part( 'loop'), since there will be no posts, just static pages?
Actually, pages also use the loop to display contents, but there will only be one "post" to loop through. Pages are treated almost exactly the same way as single posts as far as reading and rendering content goes. If you're creating your own <code> page.php </code> file for a theme, take a look first at how Twenty Ten is put together. It's always easier to learn from others than to reinvent the wheel.
How to display a page?
wordpress
I am a little confused about that. If I want tags/1.2.3 to be available for download instead of the one in trunk, how do I do that? In the FAQ, it says that I should change stable tag to 1.2.3 in trunk/readme.txt. I did that but WPD is still showing the old version in the trunk. I thought it would automatically package tags/1.2.3 after changing stable tag in trunk/readme.txt. Or I am doing it wrong?
you have to commit the changes to the /trunk directory yourself, changing the version number in the /trunk/readme.txt is not going to do this on its own. Update Whenever i update a version say from 1.0.0 to 2.0.0 i first create a directory in /tags and name it just like the last version 1.0.0 the i copy everything from /trunk to it so if someone wants an older version he can get it. the i just commit any changes of the new version to /trunk so basically trunk holds only the latest version (no need to create a new directory in trunk.)
Which directory in my plugin repo does Wordpress Plugin Directory package?
wordpress
Is there a nice way to load a js file based on the post type being viewed? I have a supplier which has a map on it but I only want the load the js when a single one is being viewed. I load the script in my functions.php file.
If you hook onto a later action such as <code> template_redirect </code> , you should be able to check the query vars to determine if your specific post type is being viewed. <code> add_action( 'template_redirect', 'example_callback' ); function example_callback() { if( is_single() &amp;&amp; get_query_var('your-posttype') ) wp_enqueue_script( .. your args .. ); } </code> Or alternatively like this... <code> add_action( 'template_redirect', 'example_callback' ); function example_callback() { if( is_single() &amp;&amp; get_query_var('post_type') &amp;&amp; 'your-type' == get_query_var('post_type') ) wp_enqueue_script( .. your args .. ); } </code> Hope that helps.
Load scripts based on post type
wordpress
How do I query_posts and only show results if a custom field is not empty or has a value. I want to put in a url in a custom field and only show these pages if there is a url? current code but I can't figure out the rest: $args = array( 'posts_per_page' => '10', 'post_type' => 'programmes', 'orderby' => 'meta_value_num', 'meta_key' => 'popularityfig', 'order' => 'DESC', );
Try this code: <code> $args = array( 'posts_per_page' =&gt; '10', 'post_type' =&gt; 'programmes', 'meta_key' =&gt; 'popularityfig', 'meta_value' =&gt; '', 'meta_compare' =&gt; '!=', 'order' =&gt; 'DESC' ); </code> There're 2 arguments you might want to note in the code: <code> meta_value </code> and <code> meta_compare </code> . Using <code> meta_compare </code> with operator <code> != </code> will exclude posts with empty meta value.
query_posts and only show results if a custom field is not empty
wordpress
I'm looking for the action hook corresponding to the click on the "Add page" link. Any idea? Thanks !
If you want to target the admin page that displays the post editor, you'll likely need to hook to two places whether it's for a script or style. You'd use the top two for scripts and the bottom two for styles. <code> // Script action for the post new page add_action( 'admin_print_scripts-post-new.php', 'example_callback' ); // Script action for the post editting page add_action( 'admin_print_scripts-post.php', 'example_callback' ); // Style action for the post new page add_action( 'admin_print_styles-post-new.php', 'example_callback' ); // Style action for the post editting page add_action( 'admin_print_styles-post.php', 'example_callback' ); </code> If you wanted to target a particular post type, simply global <code> $post_type </code> inside your callback function, like so.. <code> function example_callback() { global $post_type; // If not the desired post type bail here. if( 'your-type' != $post_type ) return; // Else we reach here and do the enqueue / or whatever } </code> If you're enqueuing scripts(not styles) specifically there is a hook that runs earlier called <code> admin_enqueue_scripts </code> which passes on the hook as the first arg, so you could also do it like this for scripts..(if you were hooking onto <code> admin_enqueue_scripts </code> instead of the two <code> admin_print_scripts </code> actions above). <code> function example_callback( $hook ) { global $post_type; // If not one of the desired pages bail here. if( !in_array( $hook, array( 'post-new.php', 'post.php' ) ) ) return; // If not the desired post type bail here. if( 'your-type' != $post_type ) return; // Else we reach here and do the enqueue / or whatever } </code> These hooks exist exactly for this type of thing, you shouldn't need to fire things as early as <code> admin_init </code> unless your specific use case dictates a requirement to. If you're unsure, chances are you don't need to fire your code that early.
Is there an "Add Page" hook?
wordpress
i am working on a theme in which points are added in user meta when he does a post... it works fine but the problem is when a post is deleted by the admin then the point should be reduced and the author should get intimation . The main problem is getting the author id of the post and doing function after the post is deleted.... the code i am trying is <code> function deletePointFromUser($post_ID) { global $wpdb; $authorid = $wpdb-&gt;get_var('SELECT post_author FROM wp_posts WHERE post_id = $post_ID'); $currentPointNumber = get_usermeta($authorid, 'points'); //Delete 1 to the current Point Score $newPointNumber = $currentPointNumber - 1; update_usermeta( $authorid, 'points', $newPointNumber); } add_action('deleted_post', 'deletePointFromUser'); </code>
Firstly, it's better to user WP functions than write your own SQL. Even though it might be a bit more expensive: <code> $post = get_post($post_ID); $authorid = $post-&gt;post_author; </code> Secondly, it's not <code> get_usermeta() </code> , but <code> get_user_meta() </code> and the complete call should include <code> true </code> as the third parameter: <code> $currentPointNumber = get_user_meta($authorid, 'points', true); </code> And then it's <code> update_user_meta() </code> , again, and you don't need to initialize a new variable, just do: <code> update_user_meta($authorid, 'points', $currentPointNumber-1); </code>
Notify Author of the post if admin deletes his post and perform some function
wordpress
I'm working on my first shortcode, examples in Shortcode API are not suitable for starters, so I'm almost sure I'm doing it wrong! My shortcode: <code> function hello( $atts ) { extract( shortcode_atts( array( 'foo' =&gt; 'something', 'bar' =&gt; 'something else', ), $atts ) ); return 'Hello, World!'; return $foo; } add_shortcode('hw', 'hello'); </code> And I want [hw foo=HEHEHE] to output: Hello, World! HEHEHE. But it displays only Hello, World! How to access &amp; echo shortcode attributes and eventually how to set the default value (I guess I've already set the default values to "something" and "something else" but I'm not sure since I have no idea how to output them.
You are return two times! The first return exit the function, so your shortcode outputs always "Hello World". Correct code: <code> function hello( $atts ) { extract( shortcode_atts( array( 'foo' =&gt; 'something', 'bar' =&gt; 'something else', ), $atts ) ); print_r($atts); // Remove, when you are fine with your atts! return 'Hello, World: '.$atts['foo']; } add_shortcode('hw', 'hello'); </code> For the second question: do a <code> print_r($atts) </code> after the extracts part!
Shortcode attributes don't appear?
wordpress
I took a code straight out of one of my themes I created, and it's a list of all 50 states in an unordered list packed into a widget you can just drag and drop on the sidebar. The problem is, when I try using this code in a PLUGIN file, I get the following error: <code> Fatal error: Call to a member function register() on a non-object in C:\xampp\htdocs\wordpress\wp-includes\widgets.php on line 431 </code> Why would it work in the theme, but not in the plugin? By the way, the active theme is NOT the theme I took the code out of. Here's my code: http://pastebin.com/ZeRWW3yb Thanks.
try replacing : <code> register_widget('States_Widget'); </code> with: <code> add_action('widgets_init', 'register_states_widget'); function register_states_widget() { register_widget('States_Widget'); } </code>
Custom Widget function in Plugin not working?
wordpress
In Which version of WordPress did term_exists() first appear?
Its since wordpress 3.0 http://codex.wordpress.org/Function_Reference/term_exists#Change_Log
Fatal error: Call to undefined function term_exists()
wordpress
I have the following code in place for a custom menu area: <code> $wp_nav_header = array( 'container' =&gt; '', 'menu_class' =&gt; 'sf-menu', 'fallback_cb' =&gt; 'wp_page_menu', 'theme_location' =&gt; 'primaryheader', 'depth' =&gt; 0,); wp_nav_menu( $wp_nav_header); </code> It works fine when there is a menu in place, and outputs: <code> &lt;div id="nav-main"&gt; &lt;div class="sf-menu"&gt; &lt;ul&gt;&lt;li... </code> However, when it's falling back , it outputs: <code> &lt;div id="nav-main"&gt; &lt;ul id="menu-default" class="sf-menu"&gt;&lt;li... </code> Needless to say, this is throwing off my design as it's adding these classes (for which I have no styling) &amp; stripping suckerfish , but makes my nav disappear (despite showing up in source). Anybody encounter this before? Thank you!
basically you are missing the container div so if you change your fallback to a custom function you can pass parameters to wp_page_menu that give you a bit of control over it and add your missing div try: <code> $wp_nav_header = array( 'container' =&gt; '', 'menu_class' =&gt; 'sf-menu', 'fallback_cb' =&gt; 'my_fallback_menu', 'theme_location' =&gt; 'primaryheader', 'depth' =&gt; 0,); wp_nav_menu( $wp_nav_header); function my_fallback_menu(){ echo '&lt;div class="sf-menu"&gt;'; $args = array( 'sort_column' =&gt; 'menu_order, post_title', 'menu_class' =&gt; '', 'include' =&gt; '', 'exclude' =&gt; '', 'echo' =&gt; true, 'show_home' =&gt; false, 'link_before' =&gt; '', 'link_after' =&gt; '' ); wp_page_menu($args); echo '&lt;/div&gt;'; } </code> Hope this helps
Fallback_cb is messing around with containers
wordpress
So I updated my plugin this morning to a new version and made some changes to the readme.txt (basic FAQ, changelog info). But the plugin site isn't reflecting the changes. I updated the 'Stable tag' to version 0.0.2, then copied the trunk file to the tags/0.0.2 directory. The svn page shows the correct readme.txt . Am I missing a step?
It normally takes at most 15 minutes before the Extend page is refreshed, so just give it a little while.
How long does it take to update a plugin page from the readme.txt?
wordpress
I'm testing Wordpress + bbPress (both latest versions): http://alexchen.info/ When I press Register it sends me to Wordpress' backend login page (I'm no longer in the site). If I click the Registration User page, and fill my username and email it sends me to Worpdpress' backend login page again and it says: <code> ERROR: The password field is empty. </code> Is there a way of letting the user just sign up while being on the site?
this Article http://digwp.com/2010/12/login-register-password-code/ provides a great tutorial on how to create you own frontend register/login/restore password forms. or if you are looking for a plugin then i've used these before and can recommend them: Ajax Login/Register Login With Ajax Theme My Login
Wordpress + bbPress registration user-unfriendly?
wordpress
Previously, in WordPress 3.0, multisites were managed through a Super-Admin section of the administration interface. The 3.1 update seems to have moved the administration of multisites to a new "Network Admin" section, which has a similar layout to the standard WP administration panels, but only contains options related to network administration. This section, however, seems to be pretty similar to the old Super-Admin section. Has there been any additional network management features added, or is the Network Admin section just a separation of options?
Basically they moved Super Admin menus and related pages out of the regular admin and into a new Network Admin screen . and the updates are: Add contextual help for Network screens Add delete support to network themes Add plugin update notifications, plugin install, plugin update to the network admin screen Admin Bar similar to that used in wordpress.com blogs ( #14772 ) Move network version of Tools-> Network to the network admin Move theme installer to the network admin for multisite installs Network Admin ( #14435 ) Network Wide Settings-> Language Settings New Network Admins page for Theme enable/disable/upgrade Pass more information to notification filters Rename Update menu to Updates in network admin Revamp User-new.php including separate caps for adding users vs. creating users, allowing supes to add via email or username, split adding existing users and creating new users into separate forms Support wildcard domains in WP_PROXY_BYPASS_HOSTS and WP_ACCESSIBLE_HOSTS Tabbed interface for site editing User Admin feature creates a separate "personal" dashboard to provide a single endpoint for accessing profile information, cross-site preferences, a launching point for accessing all of a user's blogs, collation of stats across all of a user's blogs, a place for a multisite aware quick press, etc. ( #14696 )
What is the new Network Admin section?
wordpress
After upgrading to WordPress 3.1, the comment count for each post in the Posts list now shows the PHP error <code> Warning: number_format() expects parameter 1 to be double, string given in /wp-includes/functions.php on line 155 </code> . This problem is definitely related to the Disqus comments plugin, which I suspect is manipulating the comments count. I see how I could fix this error by editing the WP core file /wp-admin/includes/class-wp-list-table.php and neutering the "get_comments_number()" function, but I'd rather find a solution for whatever is being manipulated in disqus.php. Any thoughts?
After quite a bit digging, I managed to fix it without modifying any WP core files. Essentially, Disqus usurps the comment count from WordPress and wraps it in its own with unique identifiers. Since WP is calling its own comment count when viewing the Posts lists, it's getting a string value filled with HTML rather than a plain double value with the comment count. This breaks its internal function <code> number_format_i18n() </code> . The fix is to edit disqus.php and have the function <code> function dsq_comments_number($count) </code> simply return <code> $count </code> . Just delete the extra HTML. Hopefully Disqus will roll a fix out for this soon, I've had problems with how they handle comment counts in the past. Edit: I just published a full write-up of the fix if you need more explanation: http://www.techerator.com/2011/02/fix-wordpress-3-1-and-disqus-plugin-error-when-returning-comments-count/
WordPress 3.1 and Disqus throws Warning: number_format() error in Posts List
wordpress
Is there one last filter that is ran over the widgets before they are sent out to the browser? I would like to add a filter that adds <code> rel="nofollow" </code> to all links in all widgets. For instance, I can add a filter to the text widget: <code> add_filter('widget_text', 'xrvel_nfp_modify_nofollow'); </code> But I don't want to hunt down every single hook for every widget. (Also, the RSS widget doesn't even HAVE a filter. Trac ticket submitted )
There is another thread on here that discusses a workaround. Well... the familiar php workaround when a function does not provide a "get to variable" output actually... use ob_start: http://php.net/manual/en/function.ob-start.php to just capture the output and manipulate it before sending it on its way. Leads on stackoverflow: stackexchange-url ("stackexchange-url
How to add a filter to all widget output
wordpress
I just upgraded to 3.1, and after refreshing I get the following error: Fatal error : Call to undefined function wp_cache_get() in /public_html/blog/wp-includes/functions.php on line 336 A quick google search led me to this post on WordPress support forum, however I tried disabling all plugins as suggested, and I'm using TwentyTen as my only theme. I also set <code> define('WP_CACHE', false) </code> in the config, didn't help... Any ideas before I attempt to roll everything back? Any ideas?
The problem was linked to the WP-Hive plugin , and it was (partially) resolved, when the plugin's author had fixed the problem .
Upgrade to 3.1 - Fatal error: Call to undefined function wp_cache_get()
wordpress
I am building a wordpress plugin that needs to allow the admin to upload CSS documents, and attach thumbnails. I want to know if there are any methods within wordpress that would be useful in assisting me in building an admin page that allows upload and deletion of css documents and images.
You can use the file uploader that come with Wordpress, using this guide to insert it in your meta-box: http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/ You can create some custom fields and use it to upload thumbnails or CSS to your server.
custom uploader in the admin area
wordpress
My question is about a theme named quality control which was available at wordpress repository. The plugin developer is not available at this moment and I hope I get resolution for my problem here These are the errors and many others are reporting the same error on the theme's official site Catchable fatal error: Object of class WP_Error could not be converted to string in /public_html/wp-content/themes/quality-control/single.php on line 55 and some times... Catchable fatal error: Object of class WP_Error could not be converted to string in \wp-content\themes\quality-control\inc\templates\loop.php on line 37 Could anybody help me with this? I am ready to give admin access to my site to replicate the error Update : The WordPress version I am using is 3.1 and I have tried both the 'Quality control' theme versions 1.5 and 2.0 versions . http://ffav.in is the address of web-site and these are the URLs for some example posts with errors : 1) http:// ffav.in/ticket/test/ 2) http:// ffav.in/category/uncategorized/ Thanks!
Actually there is nothing problem with the theme. I had to create at-least one 'status' before posting a ticket/post and change the Permalink settings. Most of the bugs reported by other users about this theme might have occurred with modified Permalink settings. Thanks !
Fatal error with a theme
wordpress
So I recently submitted my first plugin, and have since got a 1-star rating. Is there a place to review ratings and comments on my plugin?
There's no way to see the individual ratings, but you can see the total number of ratings and what they average out to. In the bottom left of your plugin page (in the repository) there is a section for "What others are saying", and it will display any posts from the WordPress forum talking about your plugin.
How to view plugin ratings?
wordpress
I would like to be able to easily control who registers to my blog because recently I had tons of spam users registering. I came accross the plugin Stop Spammer Registrations, but i'm not sure it is reliable enough and I would also like to have a full log of every user who was rejected by the plugin/service. Is there any good alternative? Thanks
I am a HUGE fan of the Bad Behavior plugin: Bad Behavior complements other link spam solutions by acting as a gatekeeper, preventing spammers from ever delivering their junk, and in many cases, from ever reading your site in the first place. This keeps your site's load down, makes your site logs cleaner, and can help prevent denial of service conditions caused by spammers. We started using Bad Behavior on our tech blog and noticed an immediate reduction of spam, as shown below. Here is our full article on Bad Behavior: http://www.techerator.com/2010/05/significantly-reduce-website-spam-with-bad-behavior/
What is the best way to avoid spammers registering to my blog?
wordpress
Is ther a way of displaying the facebook profile picture in the WP-FB AutoConnect widget? Like the bbPress login widget: The WP-FB AutoConnect widget doesn't show it (I think it is like this by default): (I'm using the latest version of the plugin + Wordpress 3.1 + bbpress plugin (also the latest version).
Hi JanoChen, WP-FP-AutoConnect create a function that gets the Facebook Profile image and outputs it as an avatar. The function is <code> jfb_wp_avatar </code> and it can be added to your template. You have to enable the option in the plugin settings. Here is how the function is defined in the plugin: <code> /** * Optionally replace WORDPRESS avatars with FACEBOOK profile pictures */ if( get_option($opt_jfb_wp_avatars) ) add_filter('get_avatar', 'jfb_wp_avatar', 10, 5); function jfb_wp_avatar($avatar, $id_or_email, $size, $default, $alt) { //First, get the userid if (is_numeric($id_or_email)) $user_id = $id_or_email; else if(is_object($id_or_email) &amp;&amp; !empty($id_or_email-&gt;user_id)) $user_id = $id_or_email-&gt;user_id; else if(is_string($id_or_email)) $user_id = get_user_by('email', $id_or_email ); //If we couldn't get the userID, just return default behavior (email-based gravatar, etc) if(!isset($user_id) || !$user_id) return $avatar; //Now that we have a userID, let's see if we have their facebook profile pic stored in usermeta $fb_img = get_usermeta($user_id, 'facebook_avatar_thumb'); //If so, replace the avatar! Otherwise, fallback on what WP core already gave us. if($fb_img) $avatar = "&lt;img alt='fb_avatar' src='$fb_img' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' /&gt;"; return $avatar; } </code>
Displaying the facebook profile picture in the WP-FB AutoConnect widget?
wordpress
I have added a custom field to some posts called 'frontpagerank' The plan is to order the posts by this value but first I just want to filter out any that don't use a front page rank. I have achieved this by putting the relevant posts into another array. But what to do next? Also tried a query: $the_query = new WP_Query(array( 'meta_key' => '0', 'meta_value' => '44' )); <code> while ($the_query-&gt;have_posts()) : $query-&gt;the_post(); $count++; </code> This just does nothing. This code is hard to debug!
I have added a custom field to some posts called 'frontpagerank' Then shouldn't the WP_Query args reference that key then, eg. <code> 'meta_key' =&gt; 'frontpagerank' </code> If i follow, you want to check for posts that have this key, and you're expecting a numeric value, so i'll naturally assume you don't want posts with this key(but an empty value). <code> $the_query = new WP_Query(array( 'meta_key' =&gt; 'frontpagerank', 'meta_value' =&gt; '', 'meta_compare' =&gt; '!=', 'orderby' =&gt; 'meta_value_num' )); </code> Or if you specifically want to check for posts with that meta_key where the value is above say 0, you could do.. <code> $the_query = new WP_Query(array( 'meta_key' =&gt; 'frontpagerank', 'meta_value' =&gt; '0', 'meta_compare' =&gt; '&gt;', 'orderby' =&gt; 'meta_value_num' )); </code> You can read info on the meta parameters here. http://codex.wordpress.org/Function_Reference/query_posts#Custom_Field_Parameters Info on order by to, since i added that into the above to.. ;) http://codex.wordpress.org/Function_Reference/query_posts#Order_.26_Orderby_Parameters ..any parameters you see listed for query_posts can be used inside WP_Query Then all you need do is loop over that data like you had earlier.. <code> // Note i made the correction you commented on, yes that's need to match while( $the_query-&gt;have_posts() ) : $the_query-&gt;the_post(); // do whatever endwhile; </code> Hope that helps.
Filter or order based on custom field
wordpress
i'm looking for a good and easy way to have a custom post type "event" that can have multiple dates. (I have tested about 20 plugins). I think i have no problem building a metabox allowing the user to duplicate the field group "date and time" multiple times. But how would a query look like that creates a chronological list of events from the meta data? (The project is a playing schedule for a theatre. Productions play on several dates.) Thank you!
Here's a plan: Store the dates as individual custom fields with the same meta_key (ex: start_date) JOIN the wp_posts table with the wp_postmeta table, without a GROUP BY (to allow the same event to appear more than once) ORDER BY start_date The full query would look like this: <code> SELECT wp_posts.*, meta_value AS start_date FROM wp_posts INNER JOIN wp_postmeta ON (ID = post_ID) WHERE post_type = 'event' AND post_status = 'publish' AND meta_key = 'start_date' ORDER BY start_date </code> PS: This requires you store the date in YYYY-MM-DD format, which you should do anyway, for compatibility with mysql2date() etc.
Custom Post Type “Event”: chronological list of recurring events
wordpress
What is the correct way to add a custom filter (a dropdown box in this case) to the admin user list (wp-admin/users.php)? There are no filters or actions that I see to hook into that would allow me to output a select box. I know I can inject it via javascript, but I'm hoping there's a way to do it on the PHP side. I am planning on using the results of that filter int as outlined here: stackexchange-url ("How to search all user meta from users.php in the admin")
Actually found a potential way (with WP3.1), but it's a bit more involved than using filters: Since WP3.1 now uses the <code> WP_List_Class </code> to generate the admin pages, you can create your own <code> My_User_List_Table </code> class, inheriting from <code> WP_Users_List_Table </code> and in that class override the <code> extra_tablenav() </code> method. In your own method you duplicate the code from <code> WP_Users_List_Table::extra_tablenav() </code> and add your own stuff. Then you create a duplicate of <code> wp-admin/users.php </code> , modify it to use your class instead and modify the users menu entry in the admin navigation to call your duplicate instead of <code> wp-admin/users.php </code> . I'm not sure if WP3.1 now comes with easier methods to do that then the hacky solutions necessary for WP3.0. Unfortunately, all this new WP_List_Class stuff comes without good action or filter hooks, it would have been so easy had they added an <code> apply_filters() </code> call to <code> _get_list_table() </code> . Grmpf.
Add Custom Filter to Admin User list
wordpress
I have a WP site up and running for my wife and she attempted to install a text widget that linked to her Twitter account (she says HTML was taken from Twitter.com). I am not sure exactly what she did or what was going on, but now she gets the following error when going to /wp-admin of the site: <code> WordPress database error Array for query INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES ('widget_text', 'a:2:{i:2;a:0:{} s:12:"_multiwidget";i:1;}', 'yes') ON DUPLICATE KEY UPDATE `option_name` = VALUES\ (`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES (`autoload`)--SERIALIZED made by require_once, require_once, require_once, require_once, do_action, call_user_func_array, wp_widgets_init, do_action, call_user_func_array, WP_Widget_Factory-&gt;_register_widgets, WP_Widget-&gt;_register, WP_Widget-&gt;get_settings, wp_convert_widget_settings, update_option, add_option </code> I have no idea what this even means. I am running WP on a Windows Server 2008 installation with SQL Server 2008. If you need more information, I will be glad to supply it. I really am not sure how to recover her site from this. Thanks! Edit: This site has been running fine for a month now and just now blew up after adding the text widget and adding the Twitter HTML. Edit 2: I found the offending JavaScript in the wp_options (widget_text) and removed it but am still receiving the same error listing on the admin page.
ON DUPLICATE KEY UPDATE is one of several MySQL-specific things used by WP. Best I'm aware there is no equivalent in SQL-Server. You'll get a syntax error no matter unless you regexp_replace() every query sent to the DB server in order to rewrite the SQL as needed for your specific engine.
WP Database Error (Windows Server 2008 & SQL Server)
wordpress
Today morning I updated my wordpress, everything was fine, but suddenly I came to know that if I click on any post which is not having custom taxonomies selected in it, are giving me 404 pages. I thought this is due to some plugins, so I deactivated all the plugins, and then I checked, everything was working, then I activated one by one plugin and came to know the actual plugin due to which I was getting 404 is GD Custom Posts And Taxonomies Tools plugin , which I was using for creating custom Taxonomies. But my other posts were working without 404, so i dig my head more into my wordpress, and came to know that my url structure is not supporting wordpress 3.1 In my permalinks structure, I am using custom taxonomies, which was working fine till wordpress 3.0.5, My permalink structure is this <code> /%postname%/%location%/%mba_courses%/ </code> where location and mba_courses are my custom taxonomies, To make this work I am using this code: <code> add_filter('post_link', 'location_permalink', 10, 3); add_filter('post_type_link', 'location_permalink', 10, 3); function location_permalink($permalink, $post_id, $leavename) { if (strpos($permalink, '%location%') === FALSE) return $permalink; // Get post $post = get_post($post_id); if (!$post) return $permalink; // Get taxonomy terms $terms = wp_get_object_terms($post-&gt;ID, 'location'); if (!is_wp_error($terms) &amp;&amp; !empty($terms) &amp;&amp; is_object($terms[0])) $taxonomy_slug = $terms[0]-&gt;slug; else $taxonomy_slug = 'location'; return str_replace('%location%', $taxonomy_slug, $permalink); } add_filter('post_link', 'mba_courses_permalink', 10, 3); add_filter('post_type_link', 'mba_courses_permalink', 10, 3); function mba_courses_permalink($permalink, $post_id, $leavename) { if (strpos($permalink, '%mba_courses%') === FALSE) return $permalink; // Get post $post = get_post($post_id); if (!$post) return $permalink; // Get taxonomy terms $terms = wp_get_object_terms($post-&gt;ID, 'mba_courses'); if (!is_wp_error($terms) &amp;&amp; !empty($terms) &amp;&amp; is_object($terms[0])) $taxonomy_slug = $terms[0]-&gt;slug; else $taxonomy_slug = 'mba_courses'; return str_replace('%mba_courses%', $taxonomy_slug, $permalink); } </code> How can I make this work in 3.1 or is their any feature in 3.1 where I can have custom taxonomies on my permalink?
Why not post it on the dev4press.com forum? They have really good support. Milan is pretty quick to respond too. I haven't yet tried using my version of this plugin on 3.1. Just GD Press Tools.
Wordpress 3.1 problem, getting 404
wordpress
I am looking for a function that will retrieve the names and ids of all categories that will output a checkbox, or give me the data so I can perform a loop. <code> &lt;input type="checkbox" name="category" value="category_id" /&gt; Category 1 &lt;input type="checkbox" name="category" value="category_id" /&gt; Category 2 &lt;input type="checkbox" name="category" value="category_id" /&gt; Category 3 &lt;input type="checkbox" name="category" value="category_id" /&gt; Category 4 &lt;input type="checkbox" name="category" value="category_id" /&gt; Category 5 </code>
this should do it: <code> $categories = get_categories(); foreach( $categories as $category ) { echo '&lt;input type="checkbox" name=' . $category-&gt;slug . '" value="' . $category-&gt;term_id . '" /&gt; ' . $category-&gt;name . '&lt;br /&gt;' . "\n"; } </code> and you can change/order the list by feeding arguments to <code> get_categories() </code> : http://codex.wordpress.org/Function_Reference/get_categories
Return array of categories to php function
wordpress
So I upgraded to 3.1 now I have a white band above the header of my website in the frontend when I'm logged in, I know this should be the control menu, but just a white band :-(
you are correct, that is for the admin bar. add this code to functions.php to disable the admin bar if you wish <code> &lt;?php /* Disable the Admin Bar. */ remove_action( 'init', 'wp_admin_bar_init' ); ?&gt; </code> if you want to use it then check your source for <code> &lt;div id="wpadminbar"&gt; &lt;div class="quicklinks"&gt; </code> If so, then the output is good, After that, it may be css or js conflicts perhaps
Empty space instead of admin bar
wordpress
As a custom menu item wp doesn't add the class current_page_item All other links it does? <code> &lt;ul class="nav" id="menu-mainmenu"&gt;&lt;li class="menu-item menu-item-type-custom menu-item-home menu-item-21152" id="menu-item-21152"&gt;&lt;a href="http://mydomain/"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li class="menu-item menu-item-type-post_type current-menu-item page_item page-item-21154 current_page_item menu-item-21156" id="menu-item-21156"&gt;&lt;a href="http://mydomain/"&gt;Future TV Guide&lt;/a&gt;&lt;/li&gt; &lt;li class="menu-item menu-item-type-post_type menu-item-21153" id="menu-item-21153"&gt;&lt;a href="http://mydomain/"&gt;About&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code> I would like to show it as an active link
Can't you just target .current-menu-item along with .current_page_item?
How do I add (css) class to a custom link to make it current_page_item
wordpress
I have a client who is trying to inject some JS directly into a post using the web interface. The script is stripped out on the live site. I am unable to replicate this behavior on a local installation. The JS is added as expected. The main difference between my installation and the client's is that my installation is a fresh WP3 installation, whereas the client's is WP3 upgraded from WP2. Is this a configuration option or a legacy issue? Is there some other reason why this might be happening? Rich
At least in my installation, Admin and Editors are able to inject script into their posts. Authors are not able to. Author content is parsed using a plugin called KSES, which strips out disallowed HTML. The KSES plugin can be overridden or extended. Which I have done by hacking a community plugin called Extend KSES ( http://wordpress.org/extend/plugins/extend-kses/ ). Not too keen on the idea of allowing script injection, so the client should be made aware of the dangers. Rich
Injecting JavaScript into a Post with WP3.x
wordpress
I have a subfolder install of WP multisite, let's say at "domain.com". I now need to load the WP environment in subdomains of domain.com, say "sub1.domain.com", "sub2.domain.com", ... "subN.domain.com". Note that these subdomains do not correspond to WP blogs. But I do need to have access to the logged in user, the database, etc. I have set up wildcard subdomains to load a php file that will display what I need for any particular subdomain, and I am including "wp-load.php" early in that file. The problem is that near line 99 in "ms-settings.php" it redirects to the main page of the site because $_SERVER[ 'HTTP_HOST'] is the subdomain, not the main site domain. So how can I load the WP environment correctly in a non-blog subdomain? I have a prototype that works, but I'm worried about the side effects of what I'm doing so it would be great if someone who's familiar with the core could weigh in. What I am doing is pre-populating the $current_site and $current_blog globals appropriately before including "wp-load". Then, "ms-settings" doesn't try to create these and doesn't hit the code path that detects the subdomain and redirects to the front page. I can now access member information (e.g. using 'get_userdata') and $wpdb. Does this seem like a reasonable approach?
Use the defines to make it pick the site you want it to pick. You can define these four to setup the $current_site values properly: DOMAIN_CURRENT_SITE, PATH_CURRENT_SITE, SITE_ID_CURRENT_SITE, BLOG_ID_CURRENT_SITE. If you check the wpmu_current_site() function in ms-load.php, you'll see that it uses those to create the $current_site global. You may or may not have to populate the $current_blog global manually. Not sure. Try it and see. So realistically, all you have to do is add something like this before you call wp-load.php: <code> define( 'DOMAIN_CURRENT_SITE', 'example.com' ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 ); </code> With the right values for your main example.com site, of course. If you don't want to put these in the sub-domain's php files themselves, then you can do something like this in either the wp-config.php or the sunrise.php file (if you define SUNRISE to true in the wp-config.php as well, of course). <code> if ( $_SERVER['HTTP_HOST'] == 'sub1.example.com' || $_SERVER['HTTP_HOST'] == 'sub2.example.com') { define( 'DOMAIN_CURRENT_SITE', 'example.com' ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 ); } </code> That's pretty much what the sunrise file load is there for, to allow a place where you can manually override things like this. Advantage of using sunrise.php over wp-config.php for it (which also works) is that you can easily turn sunrise on and off somewhere else, for testing and debugging and such.
What is the best way to load the WP environment in a subdomain of my multisite Wordpress install?
wordpress
On lines 4-6, I've inserted three conditional statements to determine which post type the post is in so I can insert a span which I will use to insert an image. The way I wrote it isn't working. What statement would I need to use? And is there a simpler way to set this up? <code> &lt;section id="main"&gt; &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;article class="search-post" id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;?php if (is_singular('projects')) {echo'&lt;span class="search-projects"&gt;&lt;/span&gt;';} ?&gt; &lt;?php if (is_singular('videos')) {echo'&lt;span class="search-videos"&gt;&lt;/span&gt;';} ?&gt; &lt;?php if (is_singular('friends')) {echo'&lt;span class="search-friends"&gt;&lt;/span&gt;';} ?&gt; &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt; &lt;section class="search-entry"&gt; &lt;?php the_excerpt(); ?&gt; &lt;/section&gt; &lt;/article&gt; &lt;?php endwhile; endif; ?&gt; &lt;?php my_paginate_links(); ?&gt; &lt;/section&gt; </code> For categories, I usually use <code> in_category </code> . Is there something like an <code> in_post_type </code> ?
If you use <code> is_singular() </code> , you're also checking for if it's a singular item on the page. Do <code> $post-&gt;post_type == 'my-post-type' </code> instead. BTW: if you use <code> post_class() </code> you get this and more done automatically.
display span element if in certain post types
wordpress
I have a small script within theme's <code> functions.php </code> file that uses ajax, principle like this: <code> add_action('admin_head', 'rw_script'); function rw_script() { echo ' &lt;script type="text/javascript"&gt; // delete image $(".delete_image").click(function(){ var data = $(this).attr("rel"); $.post( ajaxurl, {action: 'rw_delete_image', data: data}, function(response){ alert(response); // debug } ); return false; }); }); &lt;/script&gt;'; } function delete_image() { if (isset($_POST['attach_id'])) wp_delete_attachment($_POST['attach_id']); die(); } add_action('wp_ajax_rw_delete_image', 'delete_image'); </code> It works fine. But when I turned it into OOP, the ajax doens't work: <code> class RW_Test { function __construct() { add_action('admin_head', array(&amp;$this, 'rw_script')); add_action('wp_ajax_rw_delete_image', array(&amp;$this, 'delete_image')); } function rw_script() { echo ' &lt;script type="text/javascript"&gt; // delete image $(".delete_image").click(function(){ var data = $(this).attr("rel"); $.post( ajaxurl, {action: 'rw_delete_image', data: data}, function(response){ alert(response); // debug } ); return false; }); }); &lt;/script&gt;'; } function delete_image() { if (isset($_POST['attach_id'])) wp_delete_attachment($_POST['attach_id']); die(); } } </code> The javascript works fine, i.e when I click on delete links, data is sent properly. But the action for deleting image isn't fired. Do you know how to solve this? Please help me. Thank you.
It's been a long time since this question, now my code has changed a lot. But after re-look at the code, and I think the request should be: <code> $.post( ajaxurl, {action: 'rw_delete_image', attach_id: data}, function(response){ alert(response); // debug } ); </code> not <code> {action: 'rw_delete_image', data: data} </code> .
Ajax with OOP doesn't work
wordpress
The codex says it is depreciated. As a long time plugin user, I know how annoying it is when plugins don't clean up after themselves, is it's deprecation indication that it is necessary?
If the theme or plugin that adds a widget or sidebar is removed, then essentially it's removed from the system, what is not cleared out on deactivation/removal is widget data that's stored in the option table(applicable to widgets, not sidebars). If a sidebar is removed, any widgets that were previously in that sidebar i believe get moved into the inactive widgets group, however i can't see WP doing any clean up to remove widget data from the options table(one row in the table per widget if you're curious). I did a quick test, commented out all my registered sidebars, verified i couldn't add widgets, i see this on the widget page. No Sidebars Defined The theme you are currently using isn’t widget-aware, meaning that it has no sidebars that you are able to change. For information on making your theme widget-aware, please follow these instructions. I then fire up PhpMyAdmin and check the options table, and can see various widget entries still, eg. <code> widget_categories </code> , <code> widget_text </code> and various others. So it's my impression that only thing you should ever need to clean up is widget data from widgets that may not exist on the installation anymore, ie. data will remain in the options table even when a widget is no longer registered(i also tested unregistering/removing custom widgets i have, the data remained). Option data is stored with a key based on the class name of the registered widget(this is declared in the <code> $widget_op </code> variable setup inside constructor function of the given widget class). The keys are basically just prefixed with <code> widget_ </code> and followed by the class name, for example the text widget has the following key in the options table - <code> widget_widget_text </code> . Correction: The key is derived from this part of the widget class registeration code, but prefixed with <code> widget_ </code> (eg. <code> widget_somename </code> ). <code> $this-&gt;WP_Widget('somename', __('Some Name'), $widget_ops, $control_ops); </code> Of course it's unlikely you'll know the name of widgets that get removed from the system, i just wanted to be accurate in how the option key names are determined for widgets. Hope that helps. EDIT: As per my comment on this answer, i wrote a function to output a list of possibly redundant widget entries in the options table. <code> add_action( 'load-widgets.php', 'check_for_widget_data' ); function check_for_widget_data() { add_action( 'admin_notices', 'notify_of_redundant_widgets' ); } function notify_of_redundant_widgets() { global $wp_registered_widgets, $wpdb; $names= array(); foreach( $wp_registered_widgets as $instance_key =&gt; $data ) $names[] = $data['callback'][0]-&gt;option_name; $names = array_unique($names); $stored = $wpdb-&gt;get_col("SELECT option_name FROM $wpdb-&gt;options WHERE option_name LIKE 'widget_%'"); sort($names); sort($stored); $diff = array_diff( $stored, $names ); if( empty( $diff ) ) return; echo '&lt;div class="updated"&gt;&lt;p&gt;&lt;strong&gt;Looks like there's some left over widget data in the options table.&lt;/strong&gt;&lt;br /&gt;The following rows may now be redundant.&lt;br /&gt;'; echo '&lt;ul&gt;&lt;li&gt;&amp;bull; '. implode( '&lt;/li&gt;&lt;li&gt;&amp;bull; ', $diff ) . '&lt;/li&gt;'; echo '&lt;/p&gt;&lt;/div&gt;'; } </code> Posted incase it's useful to someone..
unregister a sidebar widget
wordpress
For some reason, if I log into my WordPress dashboard, I get logged out of my bbPress forum. When I log into my bbPress forum, I get logged out of WordPress. I followed all of the instructions correctly, and the installation told me it validated my information and it's all correct, so why is it not letting me stay logged into both at the same time?
You can achieve so by following this tutorial - http://blog.ashfame.com/2009/07/integrate-bbpress-10-with-wordpress-28/ and then keeping the bbPress integration plugin active on WordPress side (it is responsible for generating bbPress admin side cookies when you login from WordPress). So see where you missed out and get it back on track. Let me know if you are stuck or lost.
WordPress and bbPress Login conflicts?
wordpress
I'm writing two plugins at the moment which need to (optionally) log stuff...lots of stuff...somewhere. Since i don't like the 'you need to have proper permissions in this and that folder' messages of some plugins, ideally, i'd like to do it in the database. But before i start creating my own db tables (which is also something i don't like for plugins to be doing), i'm wondering if WordPress has anything that could help with suchalike enterprise hidden in the dark deep of its codebase catacombs? Ta.
I created my own plugin and it's now available from in the repository . (Edit: The plugin moved to its new home under the right name, so packaging and auto-update should be fine.)
Core framework/helpers for logging stuff?
wordpress
I want to output the taxonomies associated with a post in a 'title' attribute, so it needs to be unformatted. I know about get_terms and get_terms_list, but the problem is that you need to provide which taxonomy you want to get on forehand. But what if you have an archive page which lists multiple different post_types... you don't know which taxonomies are associated with a certain post as you don't know which post-type it is. So I tried this: <code> $posttaxonomies = get_the_taxonomies(); if ($posttaxonomies) { foreach($posttaxonomies as $taxonomy) { $thetaxonomies .= $taxonomy-&gt;name . ' '; } } </code> which doesn't output anything. I know I must be doing something wrong, but am stumped with it.
if you are in the loop you can use <code> get_post_taxonomies </code> like so: <code> $taxs = get_post_taxonomies($post-&gt;ID); foreach ($taxs as $tax){ // $tax holds the taxonomy name so you can //use either get_terms or get_terms_list } </code> Update I'll try to explain better, since you don't know what the post type is and you can't tell what taxonomies are associated with that type you first get the list of taxonomies that are associated with each post (no matter what the post type is) like so: <code> $taxs = get_post_taxonomies($post-&gt;ID); </code> now $taxs is an array that holds the names of the taxonomies associated with the current post in the loop. so we can run a foreach loop to output the post specific terms for each taxonomy using get_terms or get_terms_list for example: <code> $taxs = get_post_taxonomies($post-&gt;ID); foreach ($taxs as $tax){ $before = $tax . ": "; echo get_the_term_list( $post-&gt;ID, $tax, $before, ' ', '' ); } </code> update 2 Well if you don't wont it to echo post_tags then just check and skip it and as for getting just the terms and not the formatted html use <code> wp_get_object_terms </code> instead of <code> get_the_term_list </code> so something like: <code> $taxs = get_post_taxonomies($post-&gt;ID); foreach ($taxs as $tax){ if (!$tax = "post_tags"){ //exclude tags print_r(wp_get_object_terms( $post-&gt;ID, $tax)); // its an array of the terms } } </code>
outputting posts' taxonomies: cant get 'get_the_taxonomies' working
wordpress
With the release of WordPress 3.1, I'm about to update my own WP installation. I've had a thought about the different ways one can do the update: by hand (ugh), via Subversion checkout on the server, and using the built-in updater. To this point I've used the SVN route, not sure why, possibly that was from before WP added the auto-update feature. It's a minor hassle though, as I have to log in to the server and run <code> svn up </code> to get the new release - admittedly that's not a big deal, but it's an extra step over logging into WP to apply the update. I would imagine that the WP folks have worked hard on the auto update feature and kept it as smooth as possible. With that in mind, should I just not bother with an SVN checkout to run my site, and just use the updater? Or is there any reason why I should keep using the SVN method?
If you're already using the SVN method, then keep using it. Trying to auto-upgrade an SVN site will probably fail due to all the extra .svn directories and such. Auto-upgrade doesn't do anything special or different. It's just replacing the WordPress files with the new ones. SVN will do the same thing.
Is the built-in updater the "best" way to upgrade WP installations?
wordpress
I've done my sharing of hacking themes before, especially to replace the site title with a logo, but for newest thematic theme, I can't figure out where to edit the code to add my logo. I've checked header.php and the style.css but can't figure it out. http://wordpress.org/extend/themes/thematic Appreciate any help!
The easiest way is to use a css background image for your logo. Go to line 65 of default.css and change <code> #blog-title { font-family:Arial,sans-serif; font-size:34px; font-weight:bold; line-height:40px; } </code> To This: <code> #blog-title { background: url(images/path_to_your_logo.png) no-repeat; display:block; width: 00px; /* enter logo width */ height: 00px; /* enter logo height */ text-indent: -999em; /* replaces blog title with your logo */ } </code>
How to add logo in Thematic
wordpress
I use stackoverflow very often and just found out in google about this one, Nice :D Well, i want to save my every post i write from wordpress to my 3rd (OEXChangeble) website aswell at the same time, so i need to send the info to my website, developing a plugin iguess I need basically the permalink (and i would be able to extract the rest of the params from my wesite), but better if i can get title, tags, permalink and description(or some of it) i understand by my google research that all i need to do is add something like <code> &lt;?php //header of plugin function myFunctionThatSendsMyWebsite($url){ // procedure containing a file_get_contents('myqwebsite?url=') request to my website } add_action('page_post', 'myFunctionThatSendsMyWebsite', $permalink)); ?&gt; </code> I have problems thoug finding the name of variables i have missing (marked by ???). I know that $post contains all objet, how to extract the info from it (if there is), or if it's complicated, it would be enought for me with permalink Any tip? Thanks!
I am not entirely sure what you are trying to do. But you are definitely a little off with <code> add_action() </code> . Should be something like this: <code> function myFunctionThatSendsMyWebsite($post_ID, $post) { // $post_ID and $post will have post's ID and full post object } add_action('save_post', 'myFunctionThatSendsMyWebsite', 10, 2); </code>
help intercepting save_post through plugin
wordpress
As soon as i saw the message on WPSE about the 3.1 release i immediately went a did a switch on my local installation(SVN switch). Only issue is the <code> wp-settings.php </code> is trying to include a non-existant file. Basically i'm stuck seeing the following two error messages. Warning: require(MYPATH/wp-includes/classes.php) [function.require]: failed to open stream: No such file or directory in MYPATH\wp-settings.php on line 68 Fatal error: require() [function.require]: Failed opening required 'MYPATH/wp-includes/classes.php' (include_path='.;MYPATH/usr/local/php/includes;MYPATH/local/php/pear;MYPATH/home/admin/www/plugins/pear/PEAR') in MYPATH\wp-settings.php on line 68 MYPATH is actually a real path, i've removed that from the above quoted errors. 3.1 does not contain any such file, and i've checked my trunk installation to confirm(it's not in trunk). So what's the deal, why is the settings file still trying to include this file? Maybe an oversight with the release? I could go grab a copy from 3.0.5, just want to hear what you guys have to say first(had this problem yourself?). Looks like this is a local issue, i should be getting an updated wp-settings.php file, but for some reason SVN up is giving me an older copy(must be some caching issue somewhere, i assume). I'll update the question if i figure out the problem. UPDATE No idea why, but seems the switch didn't quite take, wiping the svn folders and doing the checkout procedure again(like i first did when i set the directory to pull from the SVN) seems to have resolved the problem.
There is no reference to 'classes.php' anywhere in the WP codebase, either in the 3.1 branch or in trunk. You probably have a modified version. Do a 'svn stat' and then a 'svn diff'.
How to fix broken upgrade to 3.1
wordpress
I'm a wordpress beginner and at the moment struggling to get to grips with custom menus. I have created two menus. Wordpress tells me the theme supports two menus. I have <code> &lt;?php wp_nav_menu('menu=services_menu'); ?&gt; </code> Where I want one menu to appear. I have <code> &lt;?php wp_nav_menu('menu=left_navigation'); ?&gt; </code> Where I want the other menu to appear. I have <code> &lt;?php if ( function_exists( 'register_nav_menus' ) ) { register_nav_menus( array( 'services_menu' =&gt; 'Services menu', 'left_navigation' =&gt; 'Left vertical navigation Menu' ) ); } ?&gt; </code> In functions.php. Both menus appear under "Appearance -> menus -> Theme locations" and are associated correctly. But only the services menu ever appears, in both locations. I've read a welter of different solutions to doing this, none of which seem to have any result other than the one described above. Where am I going wrong?
The problem is that <code> wp_nav_menu() </code> should really only ever be calling <code> theme_location </code> , not <code> menu </code> . The Theme defines menu locations , and then places those menu locations in the template. The user defines menus , and assigns menus to theme locations . So, change this: <code> &lt;?php wp_nav_menu('menu=services_menu'); ?&gt; </code> ...to this: <code> &lt;?php wp_nav_menu( 'theme_location=services_menu' ); ?&gt; </code>
Can only get one of two custom menus to display
wordpress
I have my own plugin options page, but when users hit "Save" button the whole page refreshes. Is there a way of changing my script below to something that will for example popup yellow box saying "settings saved" WITHOUT page refresh? So the data will be passed trough ajax call or something like that. I've seen something like that before, but can't recall for what plugin. <code> add_action('admin_menu', 'my_plugin_menu'); function my_plugin_menu() { add_menu_page('My Plugin Options', 'Plugin Options', 'manage_options', 'my-unique-identifier', 'my_plugin_options'); } function my_plugin_options() { if (!current_user_can('manage_options')) { wp_die( __('You do not have sufficient permissions to access this page.') ); } ?&gt; &lt;form method="post" action="options.php"&gt; &lt;?php wp_nonce_field('update-options'); ?&gt; (...) &lt;input type="hidden" name="action" value="update" /&gt; &lt;input type="hidden" name="page_options" value="option1,option2,option3,etc." /&gt; &lt;input type="submit" class="button-primary" value="&lt;?php _e('Save Changes') ?&gt;" /&gt; &lt;/form&gt; </code>
Using AJAX In Your WordPress Theme Admin looks like it is kind of what you are talking about.
wp-admin - save options without refreshing?
wordpress
I've been racking my brain on this. Here is a shortcode loop I've created to display a specific post type: <code> function faq_shortcode($atts, $content = NULL) { extract(shortcode_atts(array( 'faq_topic' =&gt; '', 'faq_tag' =&gt; '', 'faq_id' =&gt; '', 'limit' =&gt; '10', ), $atts)); $faq_topic = preg_replace('~&amp;#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $faq_topic); $faq_tag = preg_replace('~&amp;#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $faq_tag); $faqs = new WP_Query(array( 'p' =&gt; ''.$faq_id.'', 'faq-topic' =&gt; ''.$faq_topic.'', 'faq-tags' =&gt; ''.$faq_tag.'', 'post_type' =&gt; 'question', 'posts_per_page' =&gt; ''.$limit.'', 'orderby' =&gt; 'menu_order', 'order' =&gt; 'ASC' )); $displayfaq= '&lt;div class="faq_list"&gt;'; while ($faqs-&gt;have_posts()) : $faqs-&gt;the_post(); $displayfaq .= '&lt;div class="single_faq"&gt;'; $displayfaq .= '&lt;h3 class="faq_question"&gt;'.get_the_title().'&lt;/h3&gt;'; $displayfaq .= '&lt;p class="faq_answer"&gt;'.get_the_content().'&lt;/p&gt;'; $displayfaq .= '&lt;/div&gt;'; endwhile; wp_reset_query(); $displayfaq .= '&lt;/div&gt;'; return $displayfaq; } add_shortcode('faq','faq_shortcode'); </code> within one of those loops there is a post that has a shortcode being used <code> function emailbot_ssc($atts, $content = null) { extract( shortcode_atts( array( 'address' =&gt; '', ), $atts ) ); ob_start(); echo '&lt;a href="mailto:'.antispambot($atts['address']).'" title="email us" target="_blank" rel="nofollow"&gt;'.$atts['address'].'&lt;/a&gt;'; $email_ssc = ob_get_clean(); return $email_ssc; } add_shortcode("email", "emailbot_ssc"); </code> the FAQ loop (code item #1) isn't parsing the shortcode. It just displays it raw.
<code> get_the_content() </code> does not have the <code> the_content </code> filters applied to it, which is where <code> do_shortcode() </code> is hooked in. Those filters are only applied in <code> the_content() </code> . Those two functions are not simply get/echo versions of each other. <code> get_the_content() </code> is lower level. This is an anomaly in the API, and is that way for historical reasons. For instance, <code> get_the_title() </code> applies the <code> the_title </code> filters. If you want the whole <code> the_content </code> filter stack applied, do: <code> apply_filters( 'the_content', get_the_content() ) </code> If you only want shortcodes applied, do: <code> do_shortcode( get_the_content() ) </code>
Post loop created via shortcode not displaying shortcode in content
wordpress
Hay, have a basic menu looking like this <code> Item 1 Item 1.1 Item 1.1.1 Item 1.1.2 Item 1.2 Item 2 Item 2.1 </code> I'm outputting this as a list using WordPresses "wp_list_pages()" function. This is working fine. However on the pages, i am list the subpages. So, when I'm on page "Item 1.1" it says "Other pages" and lists "Item 1.1.1" and "Item 1.1.2". I'm using <code> &lt;?php wp_list_pages( array('child_of'=&gt;get_the_ID(),'title_li'=&gt;'') ); ?&gt; </code> to do this. However, i only want this to output "other pages" on the subpage. I don't want to display the "other pages" on the top level pages (like "Item 1, Item 2"). Is there a way to see if the current page is a top level page?
http://codex.wordpress.org/Function_Reference/get_page If post_parent is zero, you are there.
Find out if a page has no parent
wordpress
I got some custom post types where i deregistered the "title" meta box. Now i always get "Auto Draft" as title. To avoid this i'd like to add the name of a taxonomy as the title. But how would i check if the meta box "title" exists or not?
Check the metabox global directly? <code> $wp_meta_boxes['YOURTYPE'] </code> should hold data on metaboxes for a given type. Had a quick look in <code> wp-admin/includes/template.php </code> but i can't see any convenience functions for extracting metabox information from the array so you'll probably need to create your own code to loop over or extract the necessary info from it. Of course make sure you run your code after the <code> add_meta_boxes </code> actions(else they'll likely not exist at the point you run your code).
Post edit screen: How to check if meta_box is registered?
wordpress
I'm trying to help a buddy out -- his site, on a fresh WordPress install, is behaving oddly. With default permalinks set, everything works, but with pretty permalinks set up, all of the pages on the navigation bar load as the home page. If you hover over them, the links are still in the original <code> ?page_id=x </code> form.... Any ideas why this is happening? Hosting is with Go Daddy and they are singularly unhelpful. Many thanks. Martin
In my experience, GoDaddy has been notorious for problems while setting up pretty permalinks for the first time. Are you working with a Windows or Linux GoDaddy server? The following sites may be of some help, but from what I've read you may need to have somebody at GoDaddy make changes for you if you do not have sufficient privileges. http://www.wpressurecooker.com/permalinks/2009/08/24/pretty-permalinks-with-godaddy-windows-hosting/ https://wordpress.org/support/topic/pretty-permalink-trouble http://bbpress.org/forums/topic/pretty-permalinks-not-working
All pages load the home page if pretty permalinks are used
wordpress
I have a WordPress blog installed on my machine. I got a strange requirement from my team but I don't know how I should implement it: blog pages should be segregated under "blog/" or a similar sub-domain. For example: http://example.com/blog/hello-world rather than http://example.com/hello-world How should I do this? The index page of the website is the WordPress front page.
Add "blog" to your Permalink settings, like: <code> /blog/%post_title%/ </code>
How to change my URL on intranet
wordpress
Almost all themes display categories (with its permalink) by default. I am looking for similar type of code to add in my theme. From where can I get it? To create custom taxonomies, I'm using More Taxonomies plugin.
The easiest way to list terms of custom taxonomy and display them would be to use <code> &lt;?php get_the_term_list( $id, $taxonomy, $before, $sep, $after ) ?&gt; </code> For example in the loop, my custom taxonomy is 'jobs' list as li <code> &lt;ul&gt;&lt;?php get_the_term_list( $post-&gt;ID, 'jobs', '&lt;li class="jobs_item"&gt;', '', '&lt;/li&gt;' ) ?&gt;&lt;/ul&gt; </code>
How to display custom taxonomies in posts?
wordpress