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

Include posts from feature category in pre_get_posts

I have two custom taxonomy 'cities-taxonomy' and 'userfeed-taxonomy' and I am excluding all the post which has these taxonomies assigned in my blog page using pre_get_post(); Here is my query ...
0
votes
1answer
16 views

pre_get_posts with get_posts

So in the template I've multiple featured posts and sliders and 2 default loops. I use get_posts for everything except default loops (obviously). Now the issue I'm having is excluding get_posts ...
0
votes
1answer
19 views

How to reset usual $query on search page to push custom $wpdb query there?

I, recently posted 2 questions (First, Second) with no answer. I found my solution for both of them. But now it's time to fine-tune things. If I can fine-tune here, I could answer both the questions. ...
0
votes
1answer
20 views

pre_get_posts to hide everywhere posts from “Archive” category

I want to hide some posts from feeds, searches and nearly everything, apart from URL to this post. To have so called archive. Private post is also not an option because unlogged users with URL should ...
0
votes
0answers
19 views

Reduce or prevent calling of update_meta_cache

My theme calls the update_meta_cache() function 58 times per page! This function appears to run the following query based on the post in question: SELECT post_id, meta_key, meta_value -> FROM ...
1
vote
1answer
58 views

pre_get_posts: using tax_query only for certain post type

I have default post type posts (post type: post) and custom post type posts (post type: cpt). The latter has a taxonomy (cpt_tag). I would like to display on my front page all the default post type ...
0
votes
1answer
41 views

pre_get_posts all posts and custom post type with certain tag

I would like to display all the posts I have and custom post type pages if they have a certain tag on my home page. This is my code, but I can't get it to work: add_filter( 'pre_get_posts', ...
0
votes
1answer
21 views

How to conditionally pass a parameter to wordpress search to limit post types?

I have a site with a subsection containing a custom post type, "artwork" I have an overall site search working how I'd like it to - it searches all of my posts and custom post types. I would like to ...
0
votes
0answers
39 views

New WP_Query calls Pre_get_posts filter twice

On my WP theme template page, I am running a new WP_Query. It seems to be calling my pre_get_posts filter twice, which then wrecks my custom parameters. The second time the pre_get_posts filter is ...
0
votes
1answer
29 views

Insert a variable in pre_get_posts

I've searched in google with no luck. I'm trying to add a variable into this code to modifiy the category of the posts in homepage: Code Not Working: <?php $p = $_GET ['p'] ;?> <?php ...
2
votes
1answer
25 views

Sorting posts that has a meta value first then the rest of the posts

Im using the pre_get_posts hook to customize my query for a custom post type archive. Some of the posts for this custom post type have a meta key mp_micropub_accredited with the meta value of 1 and ...
6
votes
1answer
59 views

How to add taxonomy filter on the query fly?

I try to add tax query on pre_get_posts hook using following code : // Add custom posts to main query (archive and home) add_action( 'pre_get_posts', 'add_post_types_to_query' ); function ...
1
vote
1answer
30 views

Sanitize Custom Field Value in Meta Query

I'm using the pre_get_posts hook with meta_query args to filter an archive loop by dates. Basically, there is a custom post type of "events", and my users type in a date as a custom field for the ...
0
votes
1answer
36 views

Sorting Posts by custom field

I'm trying to sort my posts by the custom field artwork_title. When I use the following code, I just end up with one particular category of posts no matter what category archive I'm on. Also ...
1
vote
1answer
65 views

Date Query to Pull Current and Future Posts

I'm trying to use date_query to query posts with todays date or a future date. Think events, I don't want to show any posts which has a date before todays date. I'm using pre_get_posts and setting the ...
0
votes
0answers
27 views

Dynamically Switch Page Content

I'm trying to achieve the following: - When a user submits a form located on a page, a page dependend on the receipt he submitted should be displayed. I have the following solution (which works, but ...
0
votes
0answers
22 views

WP search in metadata post

In want to search by meta data value in post but I didn't succes. For example if I type "sound" I want to found "sounddiary" for example. Here my code: function custom_search_query( $query ) { ...
0
votes
1answer
17 views

meta field search too restrictive in pre_get_post() for custom search

I'm trying to figure out how to loosen up a custom meta field matching string search in a custom search. Basically, if the meta field of a custom post has "Whistler Bike Park, Canada" and I enter ...
0
votes
0answers
44 views

pre_get_posts with multiple post types AND a meta_key

So I am trying to customize the search a bit. The client wants the main site search to return people, projects, and posts. Not normally a problem. However for projects, only projects with a certain ...
0
votes
1answer
21 views

Another query in pre_get_post cause memory issue

I am trying to modify the main query on a taxonomy term page by using pre_get_posts action and post__in field. To add IDs to post__in field I have to run a query. When I call this query I run into a ...
0
votes
0answers
44 views

Removing taxonomy query by pre_get_posts

I would like to remove taxonomy related SQL query part from the main query. I am trying to use pre_get_posts posts_where filter. An example of original not modified query WHERE part: WHERE 1=1 AND ( ...
0
votes
1answer
40 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
29 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
71 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
71 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
36 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
61 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
30 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
34 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
63 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
69 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
28 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
37 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
55 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
37 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
44 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
48 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
61 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
141 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
28 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
53 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
101 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
102 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
110 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
386 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
66 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
35 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
428 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
197 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 ...