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

Adding a parameter to the default query

I'm using ACF to create a "Featured" post section of the index.php and I'm having trouble then excluding that post from the main query. <?php $tmp = $posts; $isPaged = ...
2
votes
1answer
42 views

Changing Posts Per Page and offset with pre_get_posts

I have a filter using pre_get_posts to change the number of posts per page from 4 on the news landing page to 8 on all other pages (page 2, 3, etc). However I don't seem to have got the offset ...
0
votes
0answers
24 views

WP_Query search by meta tags shows all results everytime

I'm using a search form with WP_Query to refine results of some custom post type. It's working well if I search by items but not with text input with . It shows all results: Code for the search ...
1
vote
1answer
48 views

pre_get_posts on custom post type

I have a custom post type which displays posts just fine on the page when I use a custom wp_query however, that breaks pagination, so I tried to use pre_get_posts instead as I'm already using that to ...
0
votes
1answer
20 views

how to get content from other site and show it?

i want to get content from other sites and show it on my WordPress site . example : i want to get Description Text from http://filehippo.com/download_adobe_reader/ and show it on my site . or add ...
-1
votes
0answers
38 views

Woocommerce custom taxonomy query pagination

I'm using this custom query on archive page for Woocoommerce taxonomy to list all products and it works: // Retrieving current page number $page = (get_query_var('paged')) ? ...
1
vote
1answer
46 views

Sorting and limitation with pre_get_posts

This is my third question regarding WP queries and pre_get_posts (sorry about that) but I cant give up one step before the full success :) So the story - my query is limiting front page posts to ...
0
votes
3answers
60 views

Using WP_Query in “parse_query” or “pre_get_post” in Posts2Posts

UPDATE: The hook is working with "classic" Wordpress filter (like post__in), so it's probably a Posts2Posts issue. I'm still looking for suggestions if someone has any idea. ORIGINAL POST I'm ...
2
votes
3answers
44 views

Change of query var in pre_get_posts not maintained

I'm creating a plugin that adds a custom feed. I am using a pre_get_posts filter to change the posts_per_page query var to -1 (to get all items of a custom post type). However, if I dump the $wp_query ...
0
votes
0answers
18 views

Change the taxonomy ID in the main query from pre_get_posts

I've a custom taxonomy in a language and I would retrieve the posts from the same taxonomy but from another language. I've the IDs. My query is SELECT SQL_CALC_FOUND_ROWS posts.ID FROM posts INNER ...
0
votes
1answer
16 views

Why the pre_get_posts hook can cause apache stopped working?

I'm having all my posts with a Custom Field named 'validity' where I'm assigning dates until the post is valid. My taxonomy archives are showing all the posts. Now I want to filter there, and exclude ...
0
votes
0answers
23 views

Widgets: Ajax Filtering and Add rewrite rules

I have built an Ajax filtering plugin for my widgets that works by adding url params through jQuery (when a link is clicked) and having pre_get_posts $_GET these values. These values then setup the ...
0
votes
0answers
10 views

alter $post variable in main query as soon as possible [duplicate]

I'm using WP with WooCommerce. For some purpose, I want to load a predefined static page (e.g. with id=5) whenever the user enters a product page (e.g. www.mysite.com/?product=my-product), by ...
0
votes
0answers
46 views

pre_get_post alter current post id

For some purpose, we want to apply a change to the Wordpress flow that affect's WooCommerce product page being displayed. When a product page is displayed (e.g. www.mysite.com/?product=my-product), ...
0
votes
1answer
19 views

Filter query posts by the count of metas for a meta key

I know it is possible to filter queries to order posts by the numeric value of a meta. For example, I store the number of total likes for a post in a single meta key : ...
1
vote
1answer
33 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
36 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
70 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
44 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
1answer
53 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
87 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
63 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
30 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
66 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
39 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
34 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
64 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
46 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
40 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
90 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
32 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
25 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
36 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
59 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
35 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
63 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
54 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
39 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
82 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
88 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
46 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
82 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
43 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
36 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
83 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
116 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
34 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
46 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
76 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 ...