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

0
votes
1answer
514 views

Exclude post type with pre_get_posts?

I am using pre_get_posts for a custom taxonomy archive display. Now I added a post type 'photo' sharing the same taxonomy with default post type. How can I exclude 'photo' posts being fetched by the ...
0
votes
0answers
48 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
2answers
172 views

WP_Error not displaying errors

I am trying to utilize WP_Error for my plugin, but nothing happens. Is this too late for WP_Error? Too early? Or am I doing something else wrong? function cpt_pre_post_publish(){ return new ...
0
votes
1answer
716 views

How to pass custom parameter to WP_Query for filtering in pre_get_posts

I have an ajax request that returns the result of a WP_Query loop. I would like to detect in pre_get_posts filter the specific wp_query instance that is used in the ajax handler. I thought placing ...
0
votes
2answers
163 views

Modified home page query does not yield expected results

Yesterday i asked how it would be best to load all existing pages and their content on front page - to create single page layout. (Single page theme) From the info on that page i created my own ...
0
votes
2answers
130 views

Exclude 2 in 3 terms of A Taxonomy from all Archives

I have read this post: Include and Exclude Taxonomies From Archives & Feeds Using 'pre_get_posts' And then I have used that function to my theme. My Taxonomy (tinh-trang) had 3 term: ...
0
votes
1answer
92 views

How to check during “pre_get_posts” if WP performing default query for specific custom template?

I want to modify default query for custom RSS template loaded by plugin that i'am writing right now. What is the best way to check - in function hooked to "pre_get_posts" - if default query for my ...
-3
votes
1answer
564 views

How to use pre_get_posts?

I am having a problem with the custom category template pagination and i search and read that using pre_get_posts fix the pagination problem. I read the pre_get_posts information in the WordPress ...
6
votes
6answers
2k 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 ...
0
votes
1answer
1k views

filter search result with custom post type meta key

The default search returns all post types, which is what I want. But for one specific custom post type I want to limit the result to a specific meta key value (a custom date that must be greater than ...
1
vote
1answer
1k views

How to get my Custom Post Type to display in Recent Posts using “pre_get_posts”

I created a Custom Post Type (call it "my-post-type"). I created an archive-my-post-type.php page for displaying all the Custom Post Types. Looking at the "Recent Posts" section of the Sidebar, I ...
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; } ...
0
votes
1answer
199 views

Replace query_posts with pre_get_posts

I have a static front page that checks if the user is logged in, and if he/she is a number of x posts from a specific category is displayed. For that I was using this code: ...
0
votes
1answer
220 views

pre_get_posts : 'post__not_in' doesn't work with global variable

I'm trying to set a post__not_in which use a global $popular variable, defined in the index.php. -index.php- $popular[] = 1 //post id=1 $popular[] = 2 //post id=2 $popular[] = 3 //post id=3 ...
0
votes
1answer
234 views

Insert/sticky specific post into Loop at specific location

I'm having a hard time determining the first direction to take with this. I'm trying to write a plugin that allows users to pick a location for a post to be inserted into the homepage. For example a ...
0
votes
1answer
68 views

Exclude page by title for non admins

I have this snippet built from a couple of sources, it works great and if the user is not an admin it hides the page with an id of 243 from being seen in the edit pages section.... add_action( ...
1
vote
2answers
566 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. ...
4
votes
1answer
1k views

Changing the meta_query of the main query based on custom query_vars and using pre_get_posts

I've registered custom rewrite rules and query_vars to use for displaying a list of events based on ISO date format. For example when a user requests the URL, http://site.com/by-date/2013-04-04/, my ...
0
votes
2answers
306 views

pre_get_posts for exclude category

This code works perfectly function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-1' ); } } add_action( ...
0
votes
1answer
48 views

Avoiding page loop

I'm doing a custom page that has multiple wp query calls, the thing is that I don't need the main query that is I don't need anything from the page contents, so in order to save load time I was ...
0
votes
1answer
111 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 ...
2
votes
2answers
2k views

Include and Exclude Taxonomies From Archives & Feeds Using 'pre_get_posts'

What I am trying to do? My blog uses a custom taxonomy called edition with terms like us-canada (6), eu (7) and india (8) -- term slug (ID). I want to make sure that posts not assigned to any ...
2
votes
1answer
320 views

Using database meta_values to calculate new post order using pre_get_posts or a 'request' hook

UPDATE: I have worked out my implementation of the selected answer at the bottom of this post. I'm implementing a sorting algorithm based on Reddit's hotness algorithm, in addition to a time-decay ...
0
votes
1answer
312 views

Custom post types loop on a page template

Hi I'm trying to make a page template that shows a list of a custom post type ordered by a meta key, I easily made it with query_posts but I am trying to do it via pre_get_posts so I made a function ...
0
votes
1answer
124 views

pre_get_posts and BBPress in Swagger Theme

In the theme I'm using there is a custom.php file where the following code issues a pre_get_post function which adds the custom post types to the original query object. I've learned that you cannot ...
1
vote
1answer
318 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
77 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 ...
0
votes
3answers
286 views

using pre_get_posts to exclude

I am trying to use pre_get_posts to exclude categories from posting to the homepage. If I do it like so it works just fine $query->set( 'cat', '-13,-7,-19,-12,-24,-21,-14'); that is hard coded ...
0
votes
1answer
167 views

pre_get_posts returning unformatted page

I ran a custom loop the other day to get some twitter information. Since I was running the code in a template and that template was being called from another loop, I was able to get the template data ...
3
votes
1answer
602 views

Using is_main_query to select custom post type on certain page

I've been trying to implement some of the ideas discussed by Andrew Nacin http://wordpress.tv/2012/06/15/andrew-nacin-wp_query/ into my workflow, specifically trying to move away from using ...
1
vote
1answer
362 views

Recommended way to drop a pending query (in pre_get_posts)?

It looks like an e-commerce plugin's core query will be of no use to me in one particular template so I would like to discard it completely in favor of my own WP_Query loops in the template. It's not ...
2
votes
1answer
112 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 ...
6
votes
2answers
1k views

What is “main query”? [duplicate]

Possible Duplicate: How to know which one is the main query? I'm curious to know what is the so called "main query"? What I have is two queries on front page. if (have_posts()) : while ...
12
votes
1answer
2k views

Sticky Posts exceed posts per page limit

I'm using pre_get_posts to adjust the number of posts displayed on my homepage. function lifelounge_query_adjust( $query ) { if ( is_home() ) { set_query_var( 'posts_per_page', 12 ); ...
16
votes
3answers
2k views

Should I use Pre Get Posts or WP_Query

I have the following query which I call in my taxonomy.php template via query_brands_geo('dealers', 'publish', '1', $taxtype, $geo, $brands); This function works perfectly. However after reading ...
2
votes
1answer
163 views

Custom post type with tags

My understanding is, that custom post types can share tags with the posts also. I have created tags and applied them to a blog post and a custom post type. Yet when I click on a tag it only returns ...
1
vote
2answers
418 views

Ordering by meta_key

I'm trying to order the main query on the 'Jobs' post type archive page. I want to order them by a meta_key so the ones which have a value (i.e. are checked as Featured') are shown first. Here's what ...
1
vote
1answer
184 views

Custom Order in WP Query

I'm trying to implement my own query ordering, here is what I came up with... $query = new WP_Query('post_type=contentboxes&include=' . $contentboxes . '&order=ASC&orderby=include' ); ...
0
votes
2answers
969 views

pre_get_posts and set

I have some functions into my pre_get_posts filter. So, the problem is that when I set a meta_query, all the menus disappear from the page. function propersearchfilter($query) { $taxarray = ...
3
votes
2answers
3k views

Can I exclude a post by meta key using pre_get_posts function?

I see many people prefer to use pre_get_posts hook instead of query_posts. The code below works and shows all posts which have meta key "featured" function featured_posts( $query ) { if ( ...
0
votes
1answer
470 views

how to restrict posts_request filter to the main query only

I'm trying to run custom sql for search results, and I'm having trouble limiting the filter to the main query without running a redundant query. I'm successfully getting results via the following: ...
1
vote
2answers
511 views

Single page theme that uses pages for the content

I'm making a one page site. On the page I want to run WP_Query three or four times to pull in those 3-4 pages. The page looks a bit like this: <div class="row"> <?php $args = array( ...
0
votes
2answers
3k views

Multiple orderby parameters in pre_get_posts() action

Referencing @Otto's response to a question I also had about ordering by multiple fields, here is what he said: Can't do it with a naive WP_Query. Use the posts_orderby filter to add your own ...
2
votes
1answer
441 views

Order posts by (hierarchical custom) taxonomy terms and term children

The scenario a custom post type wiki a (hierarchical) custom taxonomy topics a page template archive-wiki.php The situation Posts show up and get ordered by post_date (which is the default). The ...
0
votes
1answer
516 views

How to sort custom post type posts in default order by multiple fields?

I'm with a non-profit that paid for development of a custom post type plugin that will help us track endangered plants that we're keeping in cultivation, rescued from development. We're mostly happy ...
0
votes
2answers
504 views

How to apply pre_get_posts to a custom query?

How can I apply pre_get_posts to a custom query? For example, if I have: $custom_query = new WP_Query(...) //code here How can I apply the pre_get_posts for this $custom_query?
2
votes
1answer
1k views

pre_get_posts on a page

Is it possible to edit the main query on a page using the pre_get_posts filter? I tried but it doesn't seem to work. function pre_wp_queries( $query ) { // only trigger on main qyery if ( ...
2
votes
2answers
294 views

Splitting the main query in multiple loops with query_posts and/or pre_get_posts?

I have a custom post type 'events', to which I have associated a custom taxonomy 'calendar'. The calendar has 12 fixed terms, for each month of the year ( 'august', 'october', 'november, etc.). I'm ...
2
votes
1answer
1k views

Search ONLY by meta key / meta values

I'm almost there on this one. On functions.php i have this: function base_home_product_post_type( $query ) { if($query->is_search() && $_POST['box'] == 'sku') { ...
0
votes
2answers
903 views

How Do I Use WP_Query to Run This Database Query as Search Result?

I have created a search box with a drop down box of 4 options to customize the search: A general default search, no filter A custom search according to the post title for a custom post type only. A ...