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
0answers
13 views

Question on how pre_get_posts fires

I have a pre_get_posts filter which I want to run on archive page(s) for custom post-type(s): if ( ! function_exists('filter_employees_archive_query') ) { function ...
1
vote
1answer
28 views

Add Custom Post Type to Current Query

I'm trying to create a plugin which adds a new custom post type and it should be shown at the same locations as a normal post (front page, archives etc.). Is there any functions for me to retrieve ...
1
vote
0answers
75 views

Using different parameters for different queries with pre get posts in functions.php

Im using pre_get_posts for my taxonomy.php for my products and paginations to work properly. And I have my pre_get_posts in my functions.php. This is how that current code looks in my functions. ( ...
0
votes
0answers
9 views

Attempting to modify cpt archive with query var

I have a custom post type, messages (slug is watch), and I added a query var, speaker, as well as the rewrite. If the url is /watch/speaker/Speaker+Name it modifies the query to include that. If it's ...
-3
votes
1answer
32 views

Which action/filter can i use for a Member Plugin [closed]

I'm a beginner in Wordpress Plugin development. I want to write a Plugin for a Member Part on my Page. I know, that Plugins for this Problem available, but i want to create an own Plugin ;) I want to ...
0
votes
1answer
23 views

Only show certain post types in recent posts widget

I have a custom post type which has been made to show in archives using the code below in my theme's functions.php : add_filter('pre_get_posts', 'query_post_type'); function query_post_type($query) { ...
0
votes
1answer
29 views

Use pre_get_posts to display search results by meta in specific order

I have a search query that I'm limiting to search within a custom post type. When the content is returned I have it sorting by meta value. The post meta is a person's position. The function below ...
0
votes
1answer
33 views

Sort Wordpress Archive by multiple oderby arguments in pre_get_posts action

Actually this private function in my function.php works, BUT: i often get Error 500 by the Server on the first load, often it renders AFTER reloading the page. ## change the sorting order on archive ...
1
vote
1answer
31 views

multiple orderby in pre_get_posts action

I used to be able to sort query results by 2 criteria ("sort results first by status=unsold ASC then by date DESC) like this: add_action( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( ...
0
votes
1answer
28 views

pre_get_posts main_query not displaying after applying tax_query filters

Maybe someone can help me identify a problem I am experiencing with the pre_get_posts action. I have used the same code in another project before and it worked fine. I even went through line by line ...
0
votes
1answer
24 views

Pre Get Posts - Difference between conditional() and $query->conditional()?

This may be a poor question but inside pre_get_posts() is there any real difference between $query->conditional() versus just adding the conditional() ? Take the following example: /** Themes Pre ...
1
vote
3answers
66 views

Using meta_query with multiple keys and compare values

I suspect I may be asking for the moon on a stick with this, but: I have a filter for my shows custom post type. The filter uses standard taxonomies attached to shows, but also allows the user to ...
0
votes
1answer
57 views

pre_get_posts filter meta_query without conflicting existing meta_query

I have a meta_key on all posts that is designed to check the current user role and only return the post if the user has an acceptable user role. The problem I am running into is that my meta_query ...
0
votes
2answers
25 views

pre_get_posts post_meta event

I wish pre_get_posts to filter posts that appear in the archive-events.php and taxonomy-eventcat.php templates. I have a post_meta in use named o_event_start that stores a value in DATETIME ...
0
votes
2answers
76 views

Using Sessions to Filter Posts - bad thing?

I have a post type archive with filtering in a sidebar and pagination at the bottom. One of my biggest problems is that I'll always lose any $_POST filtering whenever I click pagination as the page ...
0
votes
0answers
49 views

Meta Compare (EXISTS) does not work

I want to include the posts that have a certain meta_key and exclude those that does not have that meta_key. NOT EXISTS works but EXISTS fails in the code below. function include_meta_key( $wp_query ...
1
vote
1answer
70 views

Trying to exclude first 5 posts from the first page on the homepage

I'm trying to exclude the first 5 posts from the first page on the homepage, but I'm unable to get it right. This is the patern that I'd like to follow: Page 1: Post 5, Post 6, Post 7, Post 8, Post ...
0
votes
0answers
17 views

How do I filter custom post types by custom field?

I am running ClassiPress theme and I am having a hard time getting only ads from a certain location to show. The main page has all the categories listed, but when I click on a category it shows all ...
0
votes
1answer
26 views

pre_get_posts not firing at all

I'm trying to add a custom post type into the seach facility so that it searches those posts as well as the pages on a site. I have seen the pre_get_posts function and have it set up like the below ...
1
vote
1answer
62 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
16 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
30 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
50 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
92 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
77 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
87 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
120 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
60 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
25 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
21 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
50 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
158 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
192 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
72 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
23 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
69 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
336 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
39 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
23 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
43 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
29 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
155 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
50 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
33 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
40 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
247 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
52 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
83 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
59 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