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

WP_Query, pre_get_posts and offset

I can't get my head around, why offset seems to be forwarded from custom WP_Query in page template to the main query further down?! From my functions.php /** * ::: Filter 'Custom Post Type' Archive ...
0
votes
1answer
4 views

Extend taxonomy term page with other posts

I have a simple taxonomy term page which lists posts connected to a specific term. I would inject some different (not connecting to that term) posts into that loop. I tried pre_get_posts action but no ...
0
votes
1answer
17 views

pre_get_posts having no effect on my category archive

By default, site is set to show 4 posts per page, but on a particular category (id 76) archive I want it to show 12. I've included this code in functions.php but it's not working. What am I missing ...
1
vote
2answers
45 views

Complex WP SQL Query

I have tried the following SQL query without any success. Can anybody that have a better understanding of SQL help? Here is what I am trying to achieve: Get a list of all main events (ME) where the ...
1
vote
1answer
42 views

Advanced or not so advanced pre_get_posts query

I would like to only show posts that have "now and future" children using pre_get_posts action hook. Does anyone have an idea of how to achieve this? function pre_get_posts($query) { ...
0
votes
1answer
15 views

How to use get_pages( ) correctly with 'child_of' to replace page with child page

I'm struggling to get the results I want here. After a couple hours of googling, I've decided to ask you all for help. I'm trying to look at children of the current (queried) page, and if the page ...
0
votes
1answer
29 views

How to alter the query using pre_get_posts hook and is_post_type_archive

The need: I'm trying to filter a custom post type archive using a GET parameter, so that I can split the posts in two groups depending on which terms they are tagged with. How: So far I've decided to ...
0
votes
0answers
16 views

Adding a Theme Customizer Control for Posts_Per_Page

I am trying to add a Theme Customizer Control to change the number of posts shown in my WP_Query posts_per_page, like so... <?php $posts_per_page_option = get_option( 'posts_per_page_option' ); ...
0
votes
0answers
29 views

wp_query - Modify $query to include duplicate content

I'm setting some featured content through the customizer (it's saved in theme_mod); Using the pre_get_posts hook, I'm retireving the feature pages in this way: ...
0
votes
1answer
32 views

Order posts by custom column using pre_get_posts

Is it possible to sort posts by custom column in wp_posts table (in this case, 'fav_count' column) using pre_get_posts filter? If not, is there any other way to do this before the main query is run, ...
0
votes
1answer
25 views

If orderby parameter using pre_get_posts is the same for multiple posts what fallback does the query use?

So I have 3 custom post types that I want to order by menu_order & have 'date' as the fallback parameter as the majority of posts will have the default menu order of '0'. It would be nice if ...
0
votes
0answers
20 views

Include attachments with a custom taxonomy in search

I need to include attachments in the search. So far, I have managed this by hooking into pre_get_posts and checking if it's on the search results page, I add 'attachment' to the post_type and ...
0
votes
1answer
27 views

Why query by specific date with variables doesn't return same result that with harcoded integers?

Having a blog with one post per day from monday to friday, on weekends I need to retrieve last friday post if user click the "today word" or the las thursday post if user click the "yesterday word". ...
0
votes
1answer
24 views

Search pre_get_posts filter which can handle multiple post types and categories?

I have a Search which allows users to search multiple custom post types (CPT). That works fine. BUT I would like the query to exclude specific tags from each of the CPTs. Eg. Include ( (Posts ...
0
votes
1answer
20 views

Help with SQL query, how to add taxonomie terms with value stored in options?

i need your help in making SQL What i have: custom post type ( company ) taxonomie ( category ) applyed to cpt ( and has ct section select field ) custom taxonomie ( section ) applyed to nothing ...
0
votes
1answer
35 views

pre_get_posts or $where, which one to use?

i have a custom search widget, that is searching only one custom post type that contain a meta_key that is greater than or equal to 1, in which i am gathering post_id. of all of those post_id(s), i ...
0
votes
0answers
33 views

Pre_get_posts to exclude latest posts of a custom taxonomy, can't find the error

I am trying to exclude the latest three posts which have the custom taxonomy "video" from the homepage loop. The hook I have written is the following: function main_loop_excludes($queryhome){ ...
1
vote
1answer
46 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
115 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
20 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
43 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
48 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
61 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
70 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
100 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
45 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
30 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
214 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
129 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
41 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
93 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
71 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
100 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
24 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
34 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 ...
2
votes
1answer
76 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
24 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
48 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
80 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
119 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
107 views

pre_get_posts and the blog page

I am trying to set up my new theme in a proper 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
124 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
214 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
26 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
56 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
213 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
282 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
101 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 ) { ...