Articles of wp query

Finding posts containing matching array elements in a meta field usign WP_Query

I have a metafield, that contains a series of options and writes the results to an array in a single meta field: array([0]=>’First’, [1]=>’Second’, [2]=>’Third’, ); I find posts that contain any of the array elements, and display them using WP_Query $search = new WP_Query(‘meta_key=mykey&meta_value=second’); But this doesn’t seem to work. Any idea on how […]

Custom Post Type Loop within Shortcode

I’m really at loss as to why this isn’t working: I am using a shortcode to display a query on a custom post type + taxonomy, this is the segment of it: // – arguments – $args = array( ‘post_type’ => ‘customposttypename’, ‘taxonomyname’ => ‘alpha’, ‘post_status’ => ‘publish’, ); // – query – $my_query = […]

query_posts: how to show all 'meta_value' containing a specific word?

How could you display all the post in a loop with a (custom) meta_value containing a word/phrase? for exemple get al the post where meta contains ‘test’. query_posts(‘post_type=SOME&category_name_2=SOME&meta_value= ‘Cotains the word ‘test’ ??? ‘); so when the meta tags are ‘test movie’ or just ‘test’ you get them both.?

Sorting posts DESC based on the number of comments using WP_Query

I have this unusual requirement from my client that I need to accommodate. They want to be able to view the posts with the largest number of comments first. At first I thought using a custom select query would do the trick. I had to write a subquery to but was able to use a […]

Excluding Sticky Posts from The Loop and from WP_Query() in WordPress?

The following snippet is from a sidebar widget that lists “recent posts”. Since its on the home page and I feature my lastest sticky post prominently on that page, I want to skip over the sticky in this loop. However, the post_not_in=sticky_posts has no effect. <?php $the_query = new WP_Query(“showposts=$number&offset=1&order=ASC&post_not_in=sticky_posts”); while ($the_query->have_posts()) : $the_query->the_post(); $do_not_duplicate […]

how to group custom post type posts by custom taxonomy terms

I would really appreciate if you could help me 🙂 I’m very stuck and don’t know how to proceed. I have a custom post type called event and 2 custom taxonomies registered for it: event_type with tag-like functionality (ex. of event type: yoga, voice work) event_location with category-like functionality (ex of event location: uk->brighton, london; […]

Group custom posts by custom taxonomy names

I try to display a list of custom posts grouped by categories using a solution from here (the 1st option/example). I adapted the code only a little to my needs, but it freezes (get a white display if it isn’t commented) my installation/blog, because of this line (as it seems to me): $term_ids = array_map(function($t) […]

WP_Query on custom taxonomy works fine but fails if run through wp_ajax_

I’m using WP_Query to collate some info about posts based on their custom taxonomy. My arguments are as follows: $args = array( ‘posts_per_page’=> -1, ‘post_status’ => ‘publish’ ); if ( isset($_POST[‘tag_id’]) ) : $args[‘tax_query’] = array(array( ‘taxonomy’ => ‘region’, ‘field’ => ‘id’, ‘terms’ => $_POST[‘tax_id’], )); endif; Then I loop through and collate my data. […]

WP Query with multiple categories – passing an array works?

According to the codex, to query posts that can belong to any of a collection of categories, we need to do something like this: $query = new WP_Query( array( ‘cat’ => ‘2,6,17,38’ ) ); https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters However, I have the following, which works, and I’m not sure why. $args = array( ‘cat’ => $related_cat_ids, ‘posts_per_page’ => […]

WordPress Orderby Numeric Value Not Working

I am trying to get all products from the wpsc-product post type and then display them by a custom meta field called release_date_year. However, it doesn’t appear to be ordering my posts by this custom meta value. I have read through countless blog posts, support posts on the WordPress forums and a lot of questions […]