Articles of wp query

Create unique page without header.php for json feed

I have two WordPress sites on separate domains. I need to expose the latest posts within a category via a json feed on one site that I have to use for the other site. I’ll need to hit a “hidden” url, ex: /themes/mytheme/json_api.php?cat=news to get the json response. I’d like this json feed to be […]

Order posts using a custom array

I have an array of post ids which I’m passing to query_posts using ‘post__in’. My question is how can I use the order from my array rather than ordering by ‘date’ etc?

Pass arguments to WP_Query using “set” method

I’m altering the main WP_Query to get all posts with a certain meta value using pre_get_posts, like this: add_action( ‘pre_get_posts’, ‘public_loop’ ); public function public_loop( $query ) { if ( ! is_admin() && $query->is_main_query() ) { $query->set( ‘meta_key’, ‘deadline’ ); } } Then I’m loading older posts via AJAX, so I need to create a […]

Pagination is broken and I need help fixing it

I am having an issue with pagination on a site I am working on. The client noticed that on her category pages, the pagination does not function after page 1. What I mean is that on pages 2 and onwards the posts no longer display from the WordPress loop. I was just wondering why this […]

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; […]