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

How to create a category filter on custom archive template?

I am trying to filter posts by category on a custom archive / template page. My template page currently has a custom query which displays posts from four specific categories. Then I have a select ...
2
votes
1answer
46 views

Can I disable this core query?

When a user creates/updates a post within the admin, it takes between 15 and 30 seconds for that operation to complete. The culprit appears to be this slow query: SELECT ID FROM wp_posts WHERE ...
2
votes
2answers
42 views

Limiting number of custom posts shown on taxonomy page

I am using a custom post type that uses two taxonomies "colour" and "style". I have a script (from this thread) which groups them together so when you are on a colour taxonomy page they are grouped by ...
0
votes
0answers
20 views

pre_get_posts with custom SQL

I have a scenario where there is a custom form on an archive page. I want to use pre_get_posts to modify what is displayed on the archive page, and show the paginated results. The issue is I first ...
1
vote
1answer
52 views

Display posts from only one post form in custom query and exclude in main query

I am trying to first display four posts with post-format-aside (all assigned to current tag) and then display the "real" archive (exclude post-format-aside) for the specific tag. Right now I am using ...
1
vote
1answer
35 views

Show Sticky Post at the top but do not show again in the loop?

Regarding wordpress.org - sticky posts are displayed at the top but they also appear again in the loop. For the main loop on my homepage I want to display the sticky posts at the top BUT I don't ...
0
votes
0answers
16 views

Add a banner image after first post, across the WordPress website [duplicate]

I am looking for a way to add a banner image after first post across the website. If it was about adding a banner on one page only, homepage or category page, then I could have done this in WordPress ...
0
votes
1answer
34 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
149 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
32 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
115 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
27 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
vote
1answer
60 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
106 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
71 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
26 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
23 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
29 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
86 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
23 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
40 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
71 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
117 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
76 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
126 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
132 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
129 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
41 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
97 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
59 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
48 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
72 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
60 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
48 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
122 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
44 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
31 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
57 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
79 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
58 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
85 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 ( ...
1
vote
1answer
82 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
5 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
52 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
98 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
109 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
64 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
105 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
56 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' ); ...