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
49 views

Conditional tag for all categories of a custom post type

I need a conditional tag which returns true on all categories added to a specific custom post type. Tried dozens of variations using the conditional tags from the Codex but still stuck. What i'm ...
0
votes
0answers
10 views

Do not count menu items in posts_per_page

Custom type posts are added to query for category page: function test__pre_get_posts( $query ) { if( !is_home() ) { if( is_main_query() || is_category() ) { $query->set( 'post_type', ...
0
votes
0answers
19 views

How to apply hook on pre_get_posts go get natural sort in listings in dashboard?

I have this code to do sorting on meta_key e_nummer ascending order in admin dashboard when listing products. /* Sort posts in wplist admin by e-nr! */ function custom_post_order($query){ ...
0
votes
0answers
23 views

Remove posts inside pre_get_posts using a custom query

I need to remove posts from admin listing, if their last child post author is different than the parent post author. I was hoping to use pre_get_posts, but can't figure out how to do this. Here's my ...
0
votes
0answers
57 views

Add input fields to Wordpress search to search custom fields

I have 2 custom fields: first and last. My goal is to add 2 new input fields (first and last) to search their respectable custom field. Here's my form code in searchform.php: <form role="search" ...
1
vote
2answers
51 views

pre_get_posts and the blog page

I am trying to set up my new theme in a propper way. I have created a custom home page for my new theme called "template-home.php" and then I created a "blog" page. I went to settings and changed my ...
0
votes
1answer
53 views

Using pre_get_posts to filter out posts, pagination problem

I'm trying to figure out how to fix my pagination problem while filtering out posts on the fly. I have a dropdown box just above the category archive that allows a user to sort or filter out posts ...
1
vote
2answers
49 views

How to display future posts - modified query still yields 404

I have a very strange problem and I am stuck. I want the single page to display posts with the post_status of publish and future. So I added this code to my functions.php in my theme: function ...
0
votes
1answer
53 views

Fetch post meta in the same query as the main loop

I have a custom post type "staff" and each as a custom field "_staff_purpose" (describing its function). I would like that the archive-staff.php template display all staff members, sorted by their ...
0
votes
1answer
23 views

How to achieve post_status__not_in

How to fetch all posts with any status except trash and draft function pre_filter( $query ){ if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == $this->post_type ) { if ...
0
votes
0answers
17 views

Re-order posts inside tax query

I have some posts having some custom fields and their value. I have custom fields like featured and expiry_date, whose values are yes/no and some date respectively. All these posts are coming under ...
0
votes
0answers
35 views

Filter WP_Query output before it is accessed (pre_get_posts)?

I have read Using pre_get_posts with WP_Query and I'm not sure where to go with it. I have a recent posts plugin which adds variables to WP_Query - one of which can be 'offset' posts. The problem is ...
0
votes
1answer
65 views

Excluding a Custom Post Type with a specific tag using pre_get_posts

I have an archive page that lists a custom post type called 'event'. I have event posts with the tag 'regular', (the tag has an id of 53). I'd like to exclude these. I tried using pre_get_posts and ...
0
votes
1answer
117 views

post__in not working with pre_get_posts, but post__not_in does work

I have an action setup on pre_get_posts which I would like to use post__in on. I used the following code as a test: $query->set('post__not_in', array(74485,1528,71460)); This works, the total ...
0
votes
1answer
43 views

using posts_where for meta data on pre_get_posts

Let's say you have some code which filters posts by using pre_get_posts e.g. add_action( 'pre_get_posts', 'be_exclude_category_from_blog' ); function be_exclude_category_from_blog( $query ) { ...
0
votes
0answers
20 views

Is it possible to order a query on one taxonomy term by the terms in another, connected taxonomy?

I've seen the negative answer in this question, Using wp_query is it possible to orderby taxonomy?, but I think I have a valid use case for something similar that's less broad than in that previous ...
2
votes
1answer
54 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
263 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
32 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
20 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
32 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
34 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
25 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
131 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
43 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
28 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
32 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
157 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
44 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
58 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
46 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
20 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
88 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
77 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
103 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
69 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
61 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
189 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
443 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
124 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
75 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
118 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
158 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
735 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
20 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
50 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
55 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
66 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
139 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
61 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() ) { ...