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

2
votes
1answer
35 views

Including only current user's posts in search

I am a new WP plugin developer. I want the search page to include only the current user's posts. I first added a new capability read_others_posts to only administrators and editors. Then I tried the ...
0
votes
1answer
16 views

Problem to show custom post type in archive page category wise

I was facing problem to show custom post type post category wise. Then i found to solve the problem . i wrote below code in function page : function my_blog_category( $query ) { if ( ...
0
votes
0answers
13 views

Set a Category As My Homepage using add_rewrite_rule

When someone visits the homepage of my wordpress site: http://www.mysite.com/wordpress/ I want them to see the contents of this page: http://www.mysite.com/wordpress/category/cars/ Attempt # 1: ...
0
votes
1answer
17 views

pre_get_posts causes Custom Posts appear under 'Pages' menu

In order to enable pagination on for custom post archive I've added pre_get_posts function. But, funnily it caused my custom posts be duplicated under 'Pages' menu. Here is the code that causes the ...
0
votes
1answer
26 views

excludeCat function reverses order of blog posts

I'm using the code below to remove category #5377 from the query on the home page. However, this code is also reversing the order of blog posts for some reason. How can I alter this code to only ...
0
votes
1answer
26 views

Using $seed on a custom post type for randomly displayed posts

I saw this link to display posts randomly without duplicating them. However how do you apply this to a custom post type? Below is what I'm using in functions to make it randomly display. ...
0
votes
1answer
20 views

Querying posts globally based on custom taxonomy with its own taxonomymeta table

I have gone through the process of creating a custom taxonomy + admin panel for a custom post type in my site. These taxonomies store various meta data in a wp_taxonomymeta table and use ...
4
votes
1answer
94 views

How to uniquely identify queries?

Today I was thinking about how to differentiate queries, mainly to create an unique identifier. In the process I played around a bit, see below code. The main idea is to do it depending on the ...
0
votes
1answer
36 views

Set a custom number of posts on the first page

I need to limit the posts shown in WordPress front page on the first page only. The reason for it is a sticky post which breaks my layout and the number of total post set up in default WP setting. I ...
0
votes
0answers
18 views

Adding custom post types to the default loop, yet only posts that has terms from the core taxonomies

I know ways to add Custom Post Types to the default loop or feeds and ways to add custom post types to the default categories and tags, all involving 'pre_get_posts' filters. I was trying to do ...
0
votes
0answers
26 views

Multiple recent Custom Post Type (CPT) on homepage issue

I have created a homepage template which shows multiple CPT's on homepage and its working fine. I have limited these CPT's to show only 1 recent post on home page using this function. function ...
0
votes
1answer
51 views

WP_Tax_Query with post_tag not working

Using the pre_get_posts hook, I'm trying to allow users to narrow down their search by limiting it to posts with certain (multiple) tags applied. This is my hook and function: ...
0
votes
1answer
38 views

Can I set my WP_Query to be a Main Query?

When I create a WP_Query it's automatically considered a "secondary query", but what if I replace my main query with a WP_Query? Can I set my WP_Query to be considered a "Main Query"? The reason I ...
0
votes
1answer
36 views

Pre_Get_Posts order DESC not registering

I've created a filter function to filter a post type items by it's meta value _item_price. The problem is that it only works in Ascending Order and I'm not sure why. My pre_get_posts function looks ...
0
votes
0answers
31 views

add_action('pre_get_posts', array(&$this, 'pre_post_search')) problem

I have used add_action('pre_get_posts', array(&$this, 'pre_post_search'));. But I can not receive value of $this in pre_post_search
0
votes
0answers
19 views

Sort pre_get_posts by multiple Simple Fields meta values? [duplicate]

I'm using the following code to pre_get_posts: function order_programs ( $query ) { // Check if on frontend and main query is modified if( ! is_admin() && $query->is_main_query() ...
1
vote
2answers
58 views

Single meta_query query using OR instead of AND in request's WHERE statement

I want the native WordPress search input to search metadata in addition to its standard title and content search, however setting a meta_query adds an AND clause to the request when what I need is an ...
1
vote
1answer
50 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
52 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
35 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
43 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
73 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
184 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
90 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
52 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
61 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
89 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
250 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
16 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
48 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
39 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
52 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
102 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
42 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
80 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
40 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
30 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
36 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
2answers
731 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
58 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
69 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
89 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
92 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
122 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
44 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
73 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
506 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
24 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
431 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
55 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( ...