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

1
vote
1answer
94 views

I am trying to hide a custom post type category to logged in users with Pre_Get_Posts

I have a custom post type in my theme called portfolio. It's categories are called project-categories. I am trying to exclude a project category for logged in users. I cannot get this to work at all. ...
0
votes
1answer
158 views

Exclude post by custom meta with pre_get_posts

I'm creating a Custom Post for an event calendar. My Custom Post has 2 custom meta fields called "event_star_date" & "event_end_date". I want to use pre_get_posts to exclude Events which their ...
0
votes
1answer
102 views

How to set back query var author_name after unset it?

I am unsetting the query var author_name for querying posts in the author template page. I am using pre_get_posts to filter the main query. After the query is run, I need to set back the author_name ...
0
votes
2answers
76 views

How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?

I am trying to change an argument in the tax query in the main WP_QUERY object for creating the archive view for my the archive of my hierarchical taxonomy. My goal is to change one of the arguments ...
0
votes
2answers
372 views

WordPress Screwing Up 'orderby' => 'meta_value_num' in 'pre_get_posts'

I have a bunch of _ai_price_int meta values set up as just numbers. This is how the table looks: meta_id, post_id, meta_key, meta_value 1309, 1111, _ai_price_int, 6550 1310, 1115, ...
0
votes
2answers
573 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 ...
1
vote
0answers
139 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 ...
1
vote
1answer
89 views

Injecting a custom sql query into a page/theme

I have written a custom sql query for our WordPress website (fairly elaborate and not achievable with the standard wordpress code) and I've got it to run via $pageposts = $wpdb->get_results($query, ...
1
vote
1answer
181 views

Obliterate the main query and replace it

There are lots of good resources on how to alter the main query, or add secondary loops... But I actually want to completely replace the main query with a different query altogether. I am hijacking ...
0
votes
2answers
194 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
1k 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
0answers
21 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
56 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
61 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
1answer
70 views

pre_get_posts returns non property object when using posts__not_in

I'm displaying posts from a category and want to show all but the first one using posts__not_in. The code below is returning a property of non object error. function modify_onthisday_cat( $query ) { ...
0
votes
2answers
160 views

Change post order by meta key, per post basis

I have a loop definition like this in functions.php: function artist_list($query) { if ( is_admin() || ! $query->is_main_query() ) { return; } // Target the artists page if ...
0
votes
0answers
68 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
1answer
140 views

How to remove attachments from main query via pre_get_posts?

I'm struggling to find a solution to the following problem. The main query should only check pages and selected custom post types for the selected post type name. address.com/flower-post-name ...
0
votes
1answer
43 views

Displaying number of search results for each post type

Using the code below, my search returns results from two different CPTs. How can I display the number of results for each CPT before displaying results? function more_posts_per_search_page( $query ) ...
0
votes
0answers
31 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 ...
1
vote
2answers
2k 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
0answers
73 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
2answers
113 views

number of posts per page + random + exclude categories

I have the following code in my home.php <?php query_posts($query_string . '&orderby=rand' . '&cat=-182,-184'); ?> query_posts seems not the best solution. What would be the best way ...
0
votes
0answers
108 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
1answer
131 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
2answers
227 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
1answer
58 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 ...
2
votes
2answers
87 views

How to create an archive for all posts that do not have a post format?

The title says it all. I need working pagination, correct post count etc. Basically a new page for posts but with a filter for post formats. Things I have tried so far: 1) Created a new rewrite rule ...
5
votes
3answers
882 views

Using meta_query on pre_get_posts to exclude a particular meta_key value

I have a simple filter running on the main query on the front page, it should be excluding all posts with a particular meta value (by only including posts who do not have the meta_key set, or those ...
0
votes
0answers
25 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
1answer
713 views

Jetpack Infinite scroll conflicting with theme's pre_get_posts custom posts_per_page

I have the current function on my theme using pre_get_posts, currently right at the bottom of my theme's functions.php file: function mytheme_portfolio_archive_pages( $query ) { if ( is_admin() ...
0
votes
1answer
59 views

pre_get_posts action doesn't work

I'm trying to load only two types of posts ( 'news' and 'reviews' ) in home page using pre_get_posts: // Load Home Page Posts( reviews and news ) function search_home_posts( $query ) { if( ...
0
votes
0answers
275 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 ...
1
vote
2answers
157 views

Why is 'pre_get_posts' having no effect?

I'm trying to use pre_get_posts for the first time without any success. It's a very simple piece of code on the index page of an otherwise empty theme, purely to get the hang of the action hook: ...
0
votes
2answers
151 views

How to second orderby in “pre_get_posts” by meta value or combine single date and time to timestamp

This is somewhat of a continued problem from another question that I had asked. Here is the original post. pre_get_post filter returns results when there should not be Since then I added an orderby ...
0
votes
0answers
114 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 ...
4
votes
1answer
623 views

is_category() in pre_get_posts strange error

I have a function that sets posts_per_page option depending on the category viewed. I discovered and error which I can't really understand: first this is how I get the error: function ...
0
votes
2answers
276 views

Replace Main Query With Custom Query

I want to replace the main query with my own custom query. The thing is I don't want to go through the hassle of manual paging. I know there's a filter posts_results but I'm not sure how to use it ...
0
votes
2answers
159 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
130 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 ...
3
votes
3answers
441 views

How would I use pre_get_posts to query another site for posts in my multisite network?

I have a multisite network of sites which should display blog content from each other if the blog post has a tag with the site name. To gather all posts within the network I use the SWT (Sitewide ...
-1
votes
2answers
108 views

Please ensure me that I'm not crazy using the pre_get_posts [closed]

function rpm_pre_get_post($query){ if($query->is_main_query()){ $query->set('meta_key', 'parent-project'); $query->set('meta_value', 'Metro-E'); } } ...
0
votes
2answers
947 views

Issue with pre_get_posts on custom post type archive pages

Overview I am creating a theme which has 2 custom post types (as custom plugins): Articles Reviews I have also created single-articles.php and archive-articles.php templates inside the plugin. ...
0
votes
1answer
647 views

Modify post filter to set custom number of posts per page and exclude child posts

I have a custom post type called "galleries," which is hierarchical. I'm using a function in my functions.php file to modify the number of posts displayed per page to 48. That part works fine, but I ...
0
votes
0answers
110 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 ...
4
votes
1answer
89 views

complex restriction of items in media library

I have a need to limit items in the media library for users without a specific capability. There are a lot of examples out there for how to limit them to only items that a given user has uploaded, ...
0
votes
1answer
306 views

Can't sort order of wp_query with 2 meta keys

I'm trying to display custom post types by excluding the sold ones but also by displaying them in alphabetical order from the county meta_key. I'm trying to use pre_get_posts but I'm not sure that ...
1
vote
0answers
95 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
1answer
47 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 ...
1
vote
1answer
390 views

Varying the number of posts per page from the first one

I want to have the index page to have a different number of posts than the rest of the pages (page 2, page 3 of the index page, as well as the archive pages). In my case I want to limit the number of ...