I've been playing around with code snippets which add meta data to admin searches.  The best snippet I've found was written by .  However, it appears to have 1, annoying bug when searching non-meta terms.   Here are some grabs from my local dev install. I've printed the 2 MySQL queries onto the screen.  View of the single CPT post I'm using to test    This is the code working as expected and allowing me to search meta data from admin    Unfortunately the code creates duplicates on non-meta matches, in this case on post title    A grab showing the post status, post type and post ancestors of dupes  !  Here is the code I'm running, it's basically the same as Stefano's, but with my crude attempts to make the query work.  /*  * Search custom fields from admin keyword searches  */  function rel_search_join( $join ) {     global $pagenow, $wpdb;     if ( is_admin() &amp;&amp; $pagenow == 'edit.php' &amp;&amp; $_GET['post_type'] == 'listings' &amp;&amp; $_GET['s'] != '') {             $join .= 'LEFT JOIN ' . $wpdb-&gt;postmeta . ' ON '. $wpdb-&gt;posts . '.ID = ' . $wpdb-&gt;postmeta . '.post_id ';     }     echo '&lt;br&gt;&lt;strong&gt;JOIN&lt;/strong&gt;: ';     print_r ( $join );     echo '&lt;br&gt;';     return $join; } add_filter('posts_join', 'rel_search_join' );  function rel_search_where( $where ) {     global $pagenow, $wpdb;     if ( is_admin() &amp;&amp; $pagenow == 'edit.php' &amp;&amp; $_GET['post_type']=='listings' &amp;&amp; $_GET['s'] != '' ) {         $where = preg_replace( "/\(\s*".$wpdb-&gt;posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/", "(".$wpdb-&gt;posts.".post_title LIKE $1) OR (".$wpdb-&gt;postmeta.".meta_value LIKE $1)", $where );         $where = str_replace( "OR wp_posts.post_status = 'pending'", "", $where );         $where = str_replace( "OR wp_posts.post_status = 'private'", "", $where );         $where = str_replace( "OR wp_posts.post_status = 'draft'", "", $where );         $where = str_replace( "OR wp_posts.post_status = 'future'", "", $where );     }     echo '&lt;br&gt;&lt;strong&gt;WHERE&lt;/strong&gt;: ';     print_r ( $where );     echo '&lt;br&gt;';     return $where; } add_filter( 'posts_where', 'rel_search_where' );
120525
I have created a custom post type and have attached some custom fields to it. Now I would like to the search that authors can perform on the custom post list screen (in the admin backend) to also be performed on the meta fields and not only look in the title and content as usual.  Where can I hook in and what code I have to use?  Example image   Stefano
43594
I want to display custom type posts from a custom taxonomy category so I did this: $news = get_posts( array(     'posts_per_page' =&gt; -1,     'post_type' =&gt; 'news',     'tax_query' =&gt; array(             'taxonomy' =&gt; 'news_category',             'field' =&gt; 'term_id',             'terms' =&gt; 82,         ),     ) );  $postslist = get_posts( $news );      foreach ($postslist as $crap) { ?&gt;      &lt;a href=&quot;&lt;?php $crap-&gt;title; ?&gt;&quot;&gt;&lt;?php $crap-&gt;title; ?&gt;&lt;/a&gt; &lt;?php }?&gt;  I get nothing from this. Why is that? I double checked the category ID and its correct. Also, I used the Custom post types plugin to register the custom taxonomy.
23832
i try to run a custom post type query to match following criteria: sort movies first by year in descending order, after that ("inside" the year order) by title alphabetically.      desired output: movie title A, 2006 movie title Z, 2006 ... movie title A, 1996 movie title Z, 1996    i use the following code:  $wp_query = new WP_Query(); $wp_query-&gt;query( array( 'post_type' =&gt; 'movies',                        'distribution' =&gt; 'companyA',                        'meta_key' =&gt; 'year',                       'orderby' =&gt; 'meta_value_num title',                         'order' =&gt; 'DESC',                        'posts_per_page' =&gt; -1,                        'post_status' =&gt; 'publish', ));   i tried several things but i can only get this "inverse" result:  movie title A, 1996 movie title Z, 1996 ... movie title A, 2006 movie title Z, 2006      if i change DESC, ASC it only changes the title sorting. but i need to apply it to the year and not to the title.  is it the right way to use two orderby values? or do i have to use a meta_query or custom SQL ?   thx in advance!  Here is the resulting SQL Query from $GLOBALS['wp_query']-&gt;request    SELECT&nbsp;wp_posts.* FROM&nbsp;&nbsp;&nbsp;wp_posts &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;INNER&nbsp;JOIN&nbsp;wp_term_relationships &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ON&nbsp;(&nbsp;wp_posts.id&nbsp;=&nbsp;wp_term_relationships.object_id&nbsp;) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;INNER&nbsp;JOIN&nbsp;wp_postmeta &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ON&nbsp;(&nbsp;wp_posts.id&nbsp;=&nbsp;wp_postmeta.post_id&nbsp;) WHERE&nbsp;&nbsp;1&nbsp;=&nbsp;1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;(&nbsp;wp_term_relationships.term_taxonomy_id&nbsp;IN&nbsp;(&nbsp;24&nbsp;)&nbsp;) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;wp_posts.post_type&nbsp;=&nbsp;'movies' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;(&nbsp;wp_posts.post_status&nbsp;=&nbsp;'publish'&nbsp;) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;(&nbsp;wp_postmeta.meta_key&nbsp;=&nbsp;'year'&nbsp;) GROUP&nbsp;&nbsp;BY&nbsp;wp_posts.id ORDER&nbsp;&nbsp;BY&nbsp;wp_postmeta.meta_value&nbsp;+&nbsp;0, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wp_posts.post_title&nbsp;DESC&nbsp;
4512
I've got a custom loop that I'm using to display some Real Estate listings that will be available within 60 days. I'm calling it with the following function:   &lt;?php  $sixtydays = date('Y/m/d', strtotime('+60 days')); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $query = new PostsOrderedByMetaQuery(array(   'post_type' =&gt; array('post', 'real-estate'),   'meta_key' =&gt; 'Time Available',   'meta_compare' =&gt; '&lt;=',   'meta_value' =&gt; $sixtydays,   'paged' =&gt; $paged,   'orderby_meta_key' =&gt; 'Price',   'orderby_order'    =&gt; 'ASC' )); ?&gt; &lt;?php while ($query-&gt;have_posts()) : $query-&gt;the_post(); ?&gt;   While the loop works great, I can't get it to paginate. It shows the first 10 (my default) posts but doesn't show the pagination. The only way to display all posts is to show them on one page by adding 'posts_per_page' =&gt; -1, I have similar loops on other pages that have no problem paginating. The only difference with this one is that there are two meta keys that are filtering the posts.   I'm using WP Page Navi for this and the rest of my pages. I'm closing the loop and adding the pagination using the following code:   &lt;?php endwhile; // End the loop. Whew. ?&gt; &lt;?php wp_pagenavi(); ?&gt; &lt;?php wp_reset_query(); ?&gt;   How can I go about fixing this?
18565
I want to use a shortcode for a table in a category description. It's my understanding that WP does not support this. I searched google and found some codes that i needed to add to the functions.php. But it's not working for me. What should I do?  Site/page:
9294
I am building a custom WordPress function/plugin that uses get_posts.  The following code returns an empy array.  I have included wp-load.php in my script.  Is there something else I am missing?    $args = array(     "posts_per_page"   =&gt; -1,     "paged"            =&gt; 0,     "orderby"          =&gt; "post_date",     "order"            =&gt; "DESC",     "post_type"        =&gt; "carellcars, ccf, attachment",     "post_status"      =&gt; "publish, inherit",     "post_author"       =&gt; "2"  );  $posts_array = get_posts($args);   print_r($posts_array);  die;   If I use arrays for post_type and _status the array is not populated, but if I use single values for post_type and _status the array is populated?  Not populated:  $args2 = array(     'posts_per_page'   =&gt; -1,     'paged'            =&gt; 0,     'orderby'          =&gt; 'post_date',     'order'            =&gt; 'DESC',     'post_type' =&gt; array('carellcars', 'ccf', 'attachment'),     'post_status'      =&gt; array('publish', 'inherit') );   Populated:  $args2 = array(     'posts_per_page'   =&gt; -1,     'paged'            =&gt; 0,     'orderby'          =&gt; 'post_date',     'order'            =&gt; 'DESC',     'post_type' =&gt;  'carellcars',     'post_status'      =&gt; 'publish' );   Update, removing "ccf" post type produces results, but I do have a ccf post_type and would like to include them.  Any ideas?      'post_type' =&gt; array('carellcars', 'attachment'),     'post_status'      =&gt; array('publish', 'inherit')
110635
the following code is supposed to store post meta of the recently published post to the variable $temp. But it doesn't, $temp is always empty. This seems to happen because "transition_post_status" fires before meta information is stored to the database.  Is there a hook that makes me able to get the post meta of the post I just published?  function myfunction($new_status, $old_status, $post) {      if ($post-&gt;post_status !== "publish" ) {        return; }       $temp = get_post_meta($post-&gt;ID);      // do something with post meta information } add_action('transition_post_status', 'myfunction', 10, 3);
72534
I am receiving this warning when I try to run a database query:     Warning: Missing argument 2 for wpdb::prepare()   The offending query is:  $result = $wpdb-&gt;get_var(     $wpdb-&gt;prepare(         "SELECT DISTINCT meta_value FROM $metatable         WHERE meta_key LIKE '%matchme%'         AND meta_value IS NOT NULL         AND meta_value &lt;&gt; ''"      ) );   Is there a way to remove the error by modifying the above query?
14271
I have two custom taxonomies applied to two custom post types. the terms list on the sidebar just fine and will list all posts associated with it. However, if you search one of the terms in specific, it doesn't bring up a post with that term.  Example:  Search for term "PQRI"  I get nothing. Any ideas? I've tried using various search plugins but they either break my custom search parameters or just don't work.
52364
I'd like to build an advanced search form for a specific custom post type, having filters for the custom post types custom fields, custom taxonomies, and for a separate custom post types properties (fields and taxonomies) which will be links to the first post type using a custom relationship field.  I've recently started off with WPs custom post types, fields, and taxonomies, I love it so far but to make the best of it I'd like to be able to search it properly. Do I need to do it manually? If so, how?  PS. If it matters, I'm using the plugins:  and .  Below I've mocked up an example of how the filtering would look and how it might relate to the post types above.
9564
I am looking to return a list of users from a database. There are hundreds of users in the db. Each user has it's own unique user_id. All of the values that I am trying to return reside in the same column (meta_value).   The database structure is as follows:  id | user_id | meta_key | meta_value   sample data is as follows:   1 | 3434 | first_name | Brandon 2 | 3434 | last_name  | Johnson 3 | 3434 | street_add | 123 main 4 | 3434 | city       | ocean beach 5 | 3434 | state      | Texas   I am trying to return the first name, last name, street_add, city, and state in one sql statement.  I'd like the output to look like:  Brandon, Johnson, 123 Main, Ocean Beach, Texas
111988
I'm using WP_Query to create 'latest posts' &amp; 'popular posts' sections on my home page. I'm trying to just pull 5 posts from 2 categories (9 &amp; 11) but it will only show posts from cat 9.  Here's the php I'm using for 'latest posts'-   &lt;ul&gt;         &lt;?php           $cat = array(9,11);         $showposts = 5;         $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;         $args=array(             'category__in' =&gt; $cat,              'showposts' =&gt; $showposts,             'paged' =&gt; $paged,             'orderby' =&gt; 'post_date',             'order' =&gt; 'DESC',             'post_status' =&gt; 'publish',            );          $the_query = new WP_Query ( $args ); //the query           $i = 0;while ($the_query-&gt;have_posts() ) : $the_query-&gt;the_post(); //start the loop         ?&gt;          &lt;?php         if($i==0){ //Sets the output for the top post         ?&gt;               &lt;li class="first-news"&gt;                 &lt;div class="post-thumbnail"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_post_thumbnail(350,187); ?&gt;&lt;/a&gt;&lt;/div&gt;                 &lt;h2 class="post-box-title"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;                 &lt;p class="post-meta"&gt;&lt;span class="tie-date"&gt;&lt;?php the_time('F jS, Y') ?&gt;&lt;/span&gt;&lt;/p&gt;                 &lt;div class="entry"&gt;&lt;?php the_excerpt(); ?&gt;&lt;/div&gt;                 &lt;div&gt;&lt;a class="more-link" href="&lt;?php the_permalink(); ?&gt;"&gt;Read More »&lt;/a&gt;&lt;/div&gt;              &lt;/li&gt;           &lt;?php             $i++;              } else { ?&gt;                  &lt;li class="other-news rar"&gt;                 &lt;div class="post-thumbnail"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_post_thumbnail(145,93); ?&gt;&lt;/a&gt;&lt;/div&gt;                 &lt;h3 class="post-box-title"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt;                 &lt;p class="post-meta"&gt;&lt;span class="tie-date"&gt;&lt;?php the_time('F jS, Y') ?&gt;&lt;/span&gt;&lt;/p&gt;            &lt;/li&gt;          &lt;?php } endwhile; //end of the loop ?&gt;         &lt;?php wp_reset_postdata(); // reset the query ?&gt;         &lt;/ul&gt;    Any suggestions?
97664
I am using a plugin called "Types" to generate custom post types for drink/food recipes. I want to show booth drink and food recipes on the same page. The posts are displaying fine, but for some reason, when you click "newer posts" or "older posts" it will bring you to a new page, but the new page will have the same posts as page 1. Anyone have any ideas? Thanks in advance!  Here's my loop:  &lt;div class="postContainer"&gt;     &lt;ol class="news postList"&gt;         &lt;?php query_posts( array('post_type' =&gt; array( 'recipe', 'drink-recipe' ), 'cat' =&gt; array('12','8'), 'showposts' =&gt; 5 )); ?&gt;         &lt;?php if( have_posts() ): ?&gt;         &lt;?php while( have_posts() ): the_post(); ?&gt;         &lt;?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post-&gt;ID ), 'single-post-thumbnail' ); ?&gt;         &lt;li class="row"&gt;             &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;" style="background-image:url('&lt;?php echo $image[0]; ?&gt;')"&gt;                 &lt;div class="seven offset-by-five"&gt;                     &lt;h3&gt;&lt;?php the_title(); ?&gt;&lt;/h3&gt;                     &lt;h4&gt;&lt;?php the_time('F j, Y') ?&gt;&lt;/h4&gt;                     &lt;?php echo the_excerpt(); ?&gt;                     &lt;div href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;" class="button"&gt;Read more&lt;/div&gt;                 &lt;/div&gt;             &lt;/a&gt;         &lt;/li&gt;         &lt;?php endwhile; ?&gt;     &lt;/ol&gt; &lt;/div&gt;  &lt;div id="pagenav"&gt;     &lt;span class="newer"&gt;&lt;?php previous_posts_link(__('Newer Posts »','blog')) ?&gt;&lt;/span&gt;     &lt;span class="older"&gt;&lt;?php next_posts_link(__('« Older Posts','blog')) ?&gt;&lt;/span&gt; &lt;/div&gt;     &lt;?php else: ?&gt;  &lt;div id="post404" class="noposts"&gt;      &lt;p&gt;&lt;?php _e('None found.','404'); ?&gt;&lt;/p&gt;  &lt;/div&gt;  &lt;?php endif; wp_reset_query(); ?&gt;  &lt;?php get_footer(); ?&gt;
56352
I'm triyng to display hotels (taxonomy which i have created) by two 'orderby' with wp_query but i'm not success.  Results looks likes:  Hotel 1 :       2 persons          5 stars Hotel 2 :       2 persons          4 stars Hotel 3 :       2 persons          3 stars Hotel 4 :       3 persons          5 stars Hotel 5 :       5 persons          5 stars Hotel 6:        10 persons         2 stars Hotel 7:        10 persons         1 star   The first 'order by' is on the number of persons(the biggest in first) and the second 'order by' is on the rating in stars (so, if several hotels have the same number of persons, the hotel with the biggest stars rating would be in first).  Below my code. I have tried to add an array inside an array with meta_query but it doesn't work.  $args=             array(                                     'post_type' =&gt; 'hotel',                                     'Services' =&gt; $Services,                                     'Town' =&gt; $Town,                                      'meta_key' =&gt; 'Number_persons',                                     'orderby' =&gt; 'meta_value_num',                                     'order' =&gt; 'ASC',                                        'meta_query' =&gt; array(                                                            array(                                                                'meta_key' =&gt; 'Rating',                                                                'orderby' =&gt; 'meta_value',                                                                'order' =&gt; 'DESC',                                                               )                                                        )                  );   $the_query = new WP_Query( $args );   Thanks a lot :)
73051
Is syntax highlighting only applied to code after the post is posted?  // test code  for (int i = 1; i &lt; 4; i++) {    s = s + "abc" + 'd' }   Also, will the formatted blocks that were shown as being separate after each time I hit Enter be merged?
23011
I have publications and I want to simply add year and month to the permalink. Currently the year and month of publication is added to the post as a meta value. I've set up publications as a custom post type and created taxonomy for the specific title of the publication. I would like the permalink to be:  publications/publication-title/year-published/month-published/name-of-post  I simply want to add the meta values for the publication year and month to the permalink.   So far, I've been able to pull the year and month published and add it to the url but unfortunately I keep getting a 404 when I try to access posts. I think I'm taking a wrong turn with one of my steps below ...  Any help would be appreciated.  These are the steps I did in the following order:   Since I was adding publication-year and publication-month to the url, I was reading that I had to make WordPress aware of these custom querystring variables. I added the following functions to register these custom variables:  function pubyear_register_rewrite_tag() {       add_rewrite_tag( '%pubyear%', '([0-9]{4})');   }    add_action( 'init', 'pubyear_register_rewrite_tag');  function pubmonth_register_rewrite_tag() {      add_rewrite_tag( '%pubmonth%', '([0-9]{2}');   }    add_action( 'init', 'pubmonth_register_rewrite_tag');    2) Added the year and month to the permalink structure:  add_filter('post_type_link', 'pub_term_permalink', 10, 4);  function pub_term_permalink($permalink, $post, $leavename, $sample) {     if ( false !== strpos( $permalink, '%publication-title%/%pubyear%/%pubmonth%' ) ) {       //get the publication-title      $publicationtype = get_the_terms( $post-&gt;ID, 'publication-type' );       //get the year of the publication      $pubyear = date('Y', get_post_meta($post-&gt;ID, 'pub_date', true));       //get the month of the publication      $pubmonth = date('m', get_post_meta($post-&gt;ID, 'pub_date', true));       $rewritecode = array(          '%publication-type%',          '%pubyear%',          '%pubmonth%',          $leavename? '' : '%postname%',      );       $rewritereplace = array(          array_pop($publicationtype)-&gt;slug,          $pubyear,          $pubmonth,          $post-&gt;post_name      );       $permalink = str_replace($rewritecode, $rewritereplace, $permalink);       }     return $permalink; }   3) Add rewrite rules:  function pub_add_rewrite_rules() {       add_rewrite_rule(  '^([^/]*)/([0-9]{4})/([0-9]{2})/([^/]+)?', 'publications/index.php?pagename=$matches[3]', 'top' );   }    add_action( 'init', 'pub_add_rewrite_rules' );   4) Made sure the custom post type is registered and includes this rewrite array:  'rewrite' =&gt; array     (             'slug' =&gt; 'publications/%publication-type%/%pubyear%/%pubmonth%',     'with_front' =&gt; false          ),
119247
I got a set of meta boxes on a custom post type. Two of them are simple input/text-type fields, that should have autocompleted input:   A) Another Custom Post Type B) Users   Now I have the problem that I need to somehow trigger the autocomplete event. So far I have this pretty simple definition:  jQuery( document ).ready( function ($)         {             $( '#some_id' ).autocomplete(             {                  minLength: 2                 ,source:    "&lt;?php print 'SOME_STRING'; ?&gt;"             } );         } );   which gives me the following answer in the console, when I enter "zz":      GET http:// localhost/wordpress/wp-admin/SOME_STRING?term=zz 404 (Not Found)   Point is that I need to run a query (as you can see above) and need to root the request for the source option/argument from autocomplete somehow to a php callback.  I hope someone can explain me how I'd get around this. Thanks (and merry christmas in case you read this :) !