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

Double loop on author page with pre_get_posts

I just learned that I should always use the default loop on archive pages and alter it with the pre_get_posts function. It's really powerful and works really well. However I'm running into an issue ...
0
votes
1answer
33 views

How to show the last and newest modified post in a custom category?

I build a plugin with pre_get_posts(), which calls my oldest modified post. But I want to see the newest modified after this posts too. Has someone an idea? This is my code: function ...
0
votes
1answer
23 views

Modify query to exclude certain ids and certain parents and its corresponding children

I'm trying to modify an admin query where I need to exclude a few pages based on two conditions: Exclude based on certain titles Exclude based on certain pages, including its children pages To ...
0
votes
1answer
37 views

Filtering out child category posts from parent category archive not working

In this example cat 5 is the parent category, and 42 is a sub-category. I the main category 5 archive I don't want any posts from sub-category 42 displaying. Why isn't this working? function ...
0
votes
0answers
5 views

Expire posts with Pre and Posts Get new WP_Query in Categories

On my website I use Get Pre Post to display active posts (without an expiration date and those who are yet to expire), and also new WP_Query use to display only posts expired in each category page. ...
0
votes
0answers
49 views

Order ascending is ignored in meta query?

I'm using pre_get_posts to alter my main query and attach a meta query to it. This is on a woocommerce products archive page (...not sure if that would make a difference). function has_upcoming_date(...
0
votes
0answers
29 views

Pre_Get_Posts: You can not group by tags in posts within a category?

With pre_get_posts you can group posts within a category: Example: Movies Category: tag Comedy Comedy Post 1 Comedy Post 2 Comedy Post 3 tag Action Action Post 1 Action Post 2 Action Post 3 And ...
0
votes
1answer
23 views

Can I use pre_get_posts to add up values from two different meta_keys?

I'm storing post meta values _likes and _dislikes in postmeta. In some cases, I want to be able to query for posts by their netto score (likes minus dislikes) and order them by it. I'm familiar with ...
2
votes
1answer
57 views

How to add custom taxonomy to search

So I have custom taxonomy called "cars". I would want that when user does search, it would also search through taxonomy. Meaning that in "cars" taxonomy if I have "Audi" term and user search with ...
1
vote
1answer
37 views

Using meta_query and custom fields within pre_get_posts to return posts within a numerical range

I'm trying to build a search page for music tracks that lets visitors: Choose the post type Choose a genre Choose a mood Specify a Beats Per Minute (bpm) range wp_dropdown_categories() is working ...
0
votes
1answer
55 views

Custom query filter not working on woocommerce category page

I am trying to make custom filter for my woocommerce website. Everything is working fine in the shop page, but when I go to the archive page the filters are not working. I am recording each filter ...
4
votes
1answer
77 views

Include post id[s] into WP_Query()

I'm assigning some posts to some users whom are not the author of those posts. Typically private posts are visible only to the post authors. So, if the author has 3 posts, on his logged in edit.php ...
0
votes
1answer
67 views

Altering the main query using get_post_meta() in pre_get_posts

I need a reliable way to get the post ID outside of the loop to use get_post_meta() in the pre_get_posts hook. So far I found out that get_queried_object_id() works for all pages except the ...
6
votes
0answers
83 views

Post injection - how to exclude the original post

This question refers to @Pieter Goosen´s extensive work about how to alter the main query using the pre_get_posts hook on true pages. It is also referenced in the codex. With his method you are able ...
1
vote
1answer
27 views

How do I edit pre_get_post for the category the user is currently in?

I've got a Woocommerce site that uses categories and products within those categories but how do I get my search form to only display results of products within the category the user currently is in. ...
1
vote
1answer
65 views

new WP_Query to get max price meta value not working

So, I'm trying to get the maximum price of all 'properties' (custom post type). $max_price_query = new WP_query(array( 'posts_per_page' => -1, 'post_status' => 'publish', 'post_type'...
1
vote
0answers
39 views

order by multiple meta keys in pre_get_posts

I want multiple orderby meta_query eg: orderby(‘_property_price’ => ‘DESC’,’_property_featured’ => ‘DESC’) This is what I am doing $query->set('meta_key',array('_property_price','...
3
votes
1answer
72 views

$query->set in pre_get_posts is unintentionally affecting the backend

So, I have a custom post type, 'properties'. I'm using archive-properties.php, and need to set some parameters on the $query. I don't want to use new WP_Query since I ran into some issues where a ...
5
votes
1answer
59 views

Custom post type by ID in root folder

i have a custom post type project the url that worked out of the box was: www.myapp.com/project/POST-ID and www.myapp.com/project/POST-SLUG now my client needs the url be available in the ...
0
votes
1answer
37 views

Limiting a filtered query

I'm struggling with this query. I have a page where I will show products launched from last month and this current month. (http://the.nett.mx/innvictus/wp/) Everything works great, but when I apply ...
0
votes
1answer
28 views

Unpublish Authors With not Fulfilled Fields

I want to unpublish profiles of users that doesn't have all extra fields that I've created filled. I use a custom meta_query in a user taxonomy in order to filter those authors, and that work, but it ...
0
votes
3answers
86 views

Custom search for custom post meta with pre_get_posts interferes with WP search

I'm making a custom post meta search with the pre_get_posts function in my Divi child theme functions.php file. The problem is that the final query gathers not only the results for my custom post ...
0
votes
0answers
26 views

pre get posts set permalink in single

Please help me I have tried a lot but still failed I made the code: function single_filter($query) { if ($query->is_single) { include( get_single_template( ) ); exit; ...
0
votes
0answers
51 views

How to use pre_get_posts filter from frontend user input (GET variables) or do_action

I'm trying to allow users to filter certain pages based on the input from a dropdown. <div class="filter-by-calories"> <h3 class="filed-title">BROWSE BY CALORIES</h3> <...
0
votes
1answer
23 views

pre_get_posts variables

Following up on Adding arg to search results page, I want to show future posts in categories but not on the home page. This code works: add_action( 'pre_get_posts', function ( $q ) { if ( !...
1
vote
1answer
62 views

Use pre_get_posts to sort meta_key by an array of values

Scenario: I have a bunch of resellers loaded under a "reseller" post type. Each of these resellers have a "rating" which is a string value like Gold, Bronze, Silver - this indicates their status as a ...
0
votes
1answer
31 views

Querying custom taxonomy on category-specific page is overwritten by function

BACKGROUND: Website is for leasing properties. Owners edit the ID of the property often. To fix this, I had to create a custom field. They needed the order on the archive page to display based on ...
1
vote
1answer
124 views

pre_get_posts order by not working

I am using the pre_get_posts hook to alter a query before it runs. The posts in question are performances and so are date and time based. I want to alter the query to get all performances which are ...
1
vote
0answers
14 views

Change the main loop Wordpress impact on the server?

I used pre_get_posts to change the loop of my Wordpress site. The idea of this loop is not show posts I define an expiration date, whose dates are added in a custom field ( postexpiry ) . These ...
-4
votes
2answers
34 views

How to var dump urls for all posts

I need to see all urls of all publish blog posts in the site. How can I get this? I want this for redirecting in .htaccess of old site to new site. This needed in anything page of site.The result is ...
0
votes
1answer
41 views

Conditional tags returning different results for different areas on a page?

I have a custom template. I want to output some JavaScript based on the type of page I am on. My current setup includes a static front page, with a template assigned it to it. This template is also a ...
1
vote
1answer
36 views

Custom Post Type Archive Error, Takes Last Post as Title and Doesn't Work

I have a cpt called Videos that suddenly doesn't work. In the archive page only appears the last video. The archive-title is not Videos anymore, it is Archive, while the browser title is the last (...
6
votes
1answer
58 views

Show only posts which can be commented OR have custom meta field

I'd like to exclude posts on the homepage which are closed for comments. This works thanks to this: Show only posts which can be commented Now I'd like to add the possibility for exceptions – to show ...
12
votes
1answer
2k views

Using pre_get_posts on true pages and static front pages

I have done quite extensive research on how to use pre_get_posts on true pages and the static front pages, and it seems that there is no fool proof method. The best option I found to date was from a ...
2
votes
1answer
35 views

Show only posts which can be commented

I have a pre_get_posts filter to show exclude some posts on the homepage. But I can't exclude the posts which are closed for commenting. How do I do this? What I have is: function ...
0
votes
1answer
49 views

Pre_get_posts comparison with custom field doesn't work

I got the following code in my functions.php. A couple of months ago it worked (or at least looks like it was), but now it isn't and I don't know what happened. // *************************** // *****...
0
votes
0answers
72 views

Custom Post Type - shows pagination (w/404) or posts_per_page query, not both

I have a custom post type of 'gallery', and I'm using a template for the archive of 'page-student-gallery.php'. My admin settings for posts shown is 5, I'd like it to show 9 on this page, of just ...
0
votes
0answers
42 views

Custom Post Search

I'm trying to modify search results for my custom post type. I have clarified that the code I am using is returning users and post ID's but no results are displayed. Essentially when a search is ...
0
votes
0answers
8 views

Add current user filter on WordPress's default celendar

I want the WordPress default calendar to only show the posts from the current logged-in user. Not the entire posts of the site. I had to hack the general-template.php to do that but really need to ...
1
vote
1answer
32 views

Sort meta-value in the sequence array in pre_get_post

I am customizing the display of posts in a category with pre_get_posts and meta_value . Each will receive a meta_value posts and wish them to be in the order of the array. I want it that way ( 1 ) ...
0
votes
1answer
107 views

Archive by custom post type and custom date field

I have created a custom post type called 'events' and custom date field called 'event_date' . I was able to create archive list for custom post type using this awesome plugin This plugin allowed ...
1
vote
0answers
56 views

Using pre_get_posts to Filter Posts

I'm trying to filter archive_research.php to show only the research with status=current. In functions.php: add_action( 'pre_get_posts', 'only_current' ); function only_current( $query ) { if ( $...
0
votes
0answers
20 views

Trying to show some custom post types

I'm using WordPress 4.3.1, and using some custom post types for information (events, publication,...). Events should appear only at sidebar (eventON plugin) and post, and publication. I'd like to show ...
0
votes
1answer
16 views

Child pages not affected by orderby

My loop won't order the child pages I'm displaying in the order I want them to, neither ASC or DESC. I've already seen many other similar issues, but those were resolved with disabling plugins (which ...
0
votes
1answer
29 views

Search for two strings in WP search

In functions.php I have the following filter: function checkForAa($query){ if($query->is_search){ $search_string = get_query_var( 's' ); if( stripos( $search_string , 'aa' ) ...
-2
votes
2answers
116 views

How to display search query as formatted text?

I am trying to display a site vistors search query on the search page. The form has custom fields so is not showing if it's "Search" and it doesnt show none of my custom fields. My search form - &...
1
vote
0answers
70 views

Why does pre_get_posts() return “date” as the orderby parameter for every sortable column?

I am stuck trying to get a custom column to sort according to a custom field. I have two custom post types: Brand and Product. I would like the Product admin screen to have a "Brand" column, and for ...
1
vote
1answer
134 views

pre_get_posts for two loops on same page

I'm using two loops on homepage, one is to show the 3 latest posts, and the other one to show the rest of the posts minus the 3 first posts. I'm using the following code for the pre_get_posts. ...
0
votes
0answers
56 views

Execute function after creating new custom post type

I have a function: function add_editor_styles() { global $post; $post_type = get_post_type(); $editor_style = get_template_directory_uri(). '/css/editor-style-' . $post_type . '.css'; ...
3
votes
1answer
125 views

SQL Statement generated by WP_Query not producing expected results

I am trying to alter WP_Query on the pre_get_posts action hook, for filtering the posts returned, depending on the built-in category and post_tag taxonomies. I would like that the only posts returned ...