Refers to a hook in WordPress Core that can be used to alter the results returned by a WP_Query based database query.

learn more… | top users | synonyms

4
votes
4answers
720 views

Sort on meta value but include posts that don't have one

I've been modifying the built in WP search using the pre_get_posts filter, allowing the user to sort the posts (including a bunch of custom post types) by different fields. The problem I'm having ...
3
votes
2answers
168 views

How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?

I added the following to my functions.php: add_action('pre_get_posts', 'keyl_get_emp_posts'); function keyl_get_emp_posts($query) { if ($query->is_main_query()) ...
1
vote
2answers
418 views

Force is_search to always TRUE

I'm extending the search functionality by adding custom query vars to the search query object via pre_get_posts so that it'll be able to include tax_query and meta_query as search conditions. ...
0
votes
2answers
26 views

Comparing arrays with meta_query in pre_get_posts

I'm working on a form for filtering a list of posts using custom fields created with the Advanced Custom Fields plugin. Because of the form, I'm using the pre_get_posts action to change the query via ...
0
votes
2answers
142 views

Prevent pre_get_posts filter on specific post type

I am running into one issue with pre_get_post filter. Actually I have 4 post types. Post, Pages, Events, and Venue. I created one custom field called city for event and venue post type. When ...
0
votes
2answers
55 views

Remove category from query (show all posts in archive.php) pre_get_posts()

I am using pre_get_posts() to allow all posts to be displayed on any category archive. This is because I will provide a javascript sorting and filtering method using isotope.js. Any category page will ...
0
votes
2answers
118 views

pre_get_post filter returns results when there should not be

I am trying to filter a CPT by an array of post ids using pre_get_post filter within my plugin. Everything works fine when there are post that match the ids, but when there are no post that match the ...
0
votes
2answers
97 views

Create Cross Promoting Categories in Wordpress Using 'pre_get_posts'

What am I trying to do? Assign more than 1 category to a post so that it would appear in each category template without 1 main category in the URL. WP's default behavior when you select more than ...
2
votes
1answer
95 views

When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?

This question is a follow up to a question I recently asked. I've implemented what seemed to be the only solution, and it seems to work (YAY!). I just need to verify that: This is really the only ...
0
votes
1answer
28 views

Setting a custom $query->query_vars['meta_key'] breaks the WordPress menu

First of all, my problem is very similar to this one: http://stackoverflow.com/questions/10629245/wordpress-menu-disappears-when-query-query-varsmeta-key-is-set However, the answer accepted for this ...
0
votes
1answer
41 views

Using pre_get_posts to rewrite search query to display posts from multiple taxonomies

This seems like it should be straightforward, but I'm stuck on it! If a user searches for 'alice', I would like to show them all posts with the custom taxonomy terms of 'bob' and 'carol', regardless ...
0
votes
1answer
58 views

Run search query again without pagination gives no results?

Update: This question isn't really relevant anymore. I switched some code, so now the filtering works. Looks like the query wasn't working, because I triggered the indexTaxonomyCounts function from ...
0
votes
1answer
36 views

How do I sort post listing by child post count?

I have two custom post types called questions and answers. The questions list includes a custom column which displays a count of the answers for each question. I need to be able to sort the listing ...
0
votes
1answer
36 views

Wordpress filter function using query modifications

I'm trying to build a filter function for the main query on a custom post type archive page. The custom post type is named "Hotel". For this custom post type i have a custom taxonomy named ...
0
votes
1answer
74 views

Hooking get_posts()

On a site this is a plugin that uses get_posts() to make a list of pages. The list is used to create a list of pages and create next page and previous page links. ( ...
0
votes
1answer
99 views

Why does this query not SELECT post IDs like a normal query would?

I have a page template, call it page-myblog.php, that I want to display an ordinary loop on. I have created a page 'myblog' in the admin area and it crops up as normal on the front end. I want to ...
0
votes
1answer
241 views

Pre_get_posts Gives 404 on Custom Post Type

I'm trying to filter the query on a sub page called "Ask Question" to list all of the recent questions submitted by users, but I get a 404 when going to the page. Flushing the permalink structure did ...
0
votes
1answer
67 views

Filter multiple different main queries on custom pages

Ok so I have multiple different page templates with a main query that I want to filter the loop for. In my example I try to use a function to filter the main loop of my site and also the main loop for ...
1
vote
0answers
74 views

Filter pre_get_posts does not modify Mine/All/Pending

Maybe I need to use a different filter, but I am using the pre_get_posts filter to filter out posts on a custom post list view. It works for the main table, but the quicklinks to (All) (Published) ...
0
votes
0answers
28 views

Removing “s” from search with custom parameters

I'm trying to do something that I thought would be quite simple and has turned out to be not simple at all. I've seen quite a few posts that look similar at first glance but none solve the issue for ...
0
votes
0answers
34 views

Add custom fields meta_query to wordpress search function

I'm trying to extend the wordpress search function to include custom fields using the pre_get_posts filter: function test_custom_search_query( $query ) { $adv_custom_fields = array( 'field_1', ...
0
votes
0answers
8 views

*Add* items in a certain taxonomy to existing posts with pre_get_posts()

I've seen somewhat similar questions on here, but not exactly what I'm trying to do. Assuming I have this: function eg_homepage_pre_get_posts( $query ) { if ( ! is_admin() && ...
0
votes
0answers
31 views

wordpress page filter problems

Hello I been working on post type filter so I can filter my content for taxonomies type but for what ever reason I can never get it to filter when I click filter public function product_filters( ...
0
votes
0answers
15 views

Pre_get_posts query conditional

I try in "pre_get_posts" filter to alter the query so i can retrieve all posts that have been published by an author AND all posts with a certain meta value no matter the author.Is that possible or i ...
0
votes
0answers
22 views

Sort posts in dashboard using custom field; also include posts where field isn't set

I'm using a pre_get_posts filter found on this question thread here, to sort a custom post type in the dashboard: function xyz_event_sort_order( $wp_query ) { if ( is_admin() ) { ...
0
votes
0answers
21 views

how a query can use local parameters in plugin function?

I've wanted to add a custom post type, so i've done a plugin to put on/off this post type. i have widgets inside the plugin in order to print posts with this custom type, that call more or less a ...
0
votes
0answers
17 views

Total Post Count showing wrongly on admin pages list after modifying the query by using `pre_get_posts` hook

I have used pre_get_posts hook and made the changes to $query to exclude page from admin pages list by ID, but the total count of posts showing in the admin pages list, is the posts number including ...
0
votes
0answers
40 views

Displaying Single Future Posts in a specific Category or Taxonomy

I want posts that are tagged with a certain term and scheduled to be posted some time in the future to be publicly available. So if I create a post, assign it a special term (category, tag, custom ...
0
votes
0answers
63 views

Using WP_Query IN pre_get_posts while searching

This is a continuation on this question. What I'm trying to do, is rerun a search query, to loop through it and index the taxonomy counts (so I can make some kind of facet search). What I do is this ...
0
votes
0answers
21 views

Load Index on “Earlier” Post, Prev and Next Links

how would i load the index of my blog at a later point in the reverse chronological feed while maintaining the chronology of the feed overall? i found this explanation of how to load the feed at a ...
0
votes
0answers
88 views

why is pre_get_posts not working

function include_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '3' ); } } add_action( 'pre_get_posts', 'include_category' ); I ...
0
votes
0answers
70 views

custom post types, pre_get_posts, wp_list_categories

So, I know I can make this work in a roundabout way, but I think I am doing something wrong in the first place. Essentially, the situation is like this. I have a custom post type, the posts of which ...
0
votes
0answers
118 views

Searching custom fields with pre_get_posts

UPDATE: 12.4.13 I'm now using a posts_where filter. It looks like this: function posts_where( $where ) { if ( is_search() ) { global $wpdb; $beds = ( ! empty( $beds ) ) ? ...
0
votes
0answers
48 views

Show private posts by group leader to members of that group across the website

Group leader - A designated user creates private posts. Group member - I want a certain subset of my users to be able to see it across the website (on taxonomy/tag pages as well as the actual single ...
0
votes
0answers
87 views

Using pre_get_posts to filter by custom fields while using static front page

I'm trying to filter a custom post type loop by several custom fields using pre_get_posts. Category pages display just fine. I'm having trouble with the static front page which for some reason ...
0
votes
0answers
42 views

Custom post type archive as home page: getting navigation to recognize the modified query

I have modified the query of the home page to call a custom post archive by the method explained here. What I can't figure out is how to get the navigation to recognize this new query and add the ...
0
votes
0answers
45 views

How to order posts by parents?

I wanted to order my post type archive by its parents (like page list in wp-admin). This is what i have tried, but no luck so far. add_action( 'pre_get_posts', 'budget_archive_data' ); function ...
0
votes
0answers
98 views

Pre Get Posts fails with more than 1 Post Type

Inside Functions.php function custom_filings_archive( $query ) { if(is_post_type_archive( 'filings' )) $query->set('post_type',array('the-reports','press-release')); return $query; } ...
-1
votes
0answers
24 views

Woocommerce conflict with pre_get_posts

I implement woocommerce in my theme but I have a conflict with my custom query that I added for my archive template. I can't figure out how to make work pre_get_posts with woocommerce activated. ...