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
33 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
0answers
19 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
52 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 ...
6
votes
1answer
239 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
32 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
39 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
32 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
35 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
6 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
25 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
41 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
33 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
18 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
15 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
20 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
68 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
43 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 ...
0
votes
1answer
117 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
43 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
99 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 ...
0
votes
1answer
76 views

Sort custom post types by last name in the backend

I have a custom post type called speakers, where post title is a speakers first- AND last name. I created it with this code: add_action( 'init', 'create_post_type' ); function create_post_type() { ...
1
vote
0answers
173 views

Slow SQL_CALC_FOUND_ROWS Query

We are experiencing very slow performance with queries that use SQL_CALC_FOUND_ROWS within the admin section of WordPress. We currently have about 125,000 posts on our site and use Varnish to cache ...
0
votes
0answers
227 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
113 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
76 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
78 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
80 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
118 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
21 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
78 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 = ...
3
votes
1answer
590 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
47 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
561 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
30 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
124 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
225 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
111 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
45 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
32 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
46 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
174 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
39 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
67 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
166 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
222 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
128 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 ...
1
vote
1answer
416 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
369 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
325 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', ...