0
votes
0answers
10 views

Do not count menu items in posts_per_page

Custom type posts are added to query for category page: function test__pre_get_posts( $query ) { if( !is_home() ) { if( is_main_query() || is_category() ) { $query->set( 'post_type', ...
0
votes
0answers
55 views

Add input fields to Wordpress search to search custom fields

I have 2 custom fields: first and last. My goal is to add 2 new input fields (first and last) to search their respectable custom field. Here's my form code in searchform.php: <form role="search" ...
1
vote
2answers
49 views

How to display future posts - modified query still yields 404

I have a very strange problem and I am stuck. I want the single page to display posts with the post_status of publish and future. So I added this code to my functions.php in my theme: function ...
0
votes
0answers
35 views

Filter WP_Query output before it is accessed (pre_get_posts)?

I have read Using pre_get_posts with WP_Query and I'm not sure where to go with it. I have a recent posts plugin which adds variables to WP_Query - one of which can be 'offset' posts. The problem is ...
2
votes
1answer
54 views

Including only current user's posts in search

I am a new WP plugin developer. I want the search page to include only the current user's posts. I first added a new capability read_others_posts to only administrators and editors. Then I tried the ...
4
votes
1answer
129 views

How to uniquely identify queries?

Today I was thinking about how to differentiate queries, mainly to create an unique identifier. In the process I played around a bit, see below code. The main idea is to do it depending on the ...
0
votes
1answer
157 views

WP_Tax_Query with post_tag not working

Using the pre_get_posts hook, I'm trying to allow users to narrow down their search by limiting it to posts with certain (multiple) tags applied. This is my hook and function: ...
0
votes
1answer
44 views

Can I set my WP_Query to be a Main Query?

When I create a WP_Query it's automatically considered a "secondary query", but what if I replace my main query with a WP_Query? Can I set my WP_Query to be considered a "Main Query"? The reason I ...
1
vote
2answers
88 views

Single meta_query query using OR instead of AND in request's WHERE statement

I want the native WordPress search input to search metadata in addition to its standard title and content search, however setting a meta_query adds an AND clause to the request when what I need is an ...
0
votes
2answers
61 views

How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?

I am trying to change an argument in the tax query in the main WP_QUERY object for creating the archive view for my the archive of my hierarchical taxonomy. My goal is to change one of the arguments ...
0
votes
0answers
20 views

*Add* items in a certain taxonomy to existing posts with pre_get_posts()

I've seen somewhat similar questions on here, but not exactly what I'm trying to do. Assuming I have this: function eg_homepage_pre_get_posts( $query ) { if ( ! is_admin() && ...
0
votes
0answers
50 views

wordpress page filter problems

Hello I been working on post type filter so I can filter my content for taxonomies type but for what ever reason I can never get it to filter when I click filter public function product_filters( ...
0
votes
0answers
54 views

Pre_get_posts query conditional

I try in "pre_get_posts" filter to alter the query so i can retrieve all posts that have been published by an author AND all posts with a certain meta value no matter the author.Is that possible or i ...
0
votes
0answers
61 views

Sort posts in dashboard using custom field; also include posts where field isn't set

I'm using a pre_get_posts filter found on this question thread here, to sort a custom post type in the dashboard: function xyz_event_sort_order( $wp_query ) { if ( is_admin() ) { ...
0
votes
0answers
31 views

how a query can use local parameters in plugin function?

I've wanted to add a custom post type, so i've done a plugin to put on/off this post type. i have widgets inside the plugin in order to print posts with this custom type, that call more or less a ...
0
votes
2answers
2k views

Prevent pre_get_posts filter on specific post type

I am running into one issue with pre_get_post filter. Actually I have 4 post types. Post, Pages, Events, and Venue. I created one custom field called city for event and venue post type. When ...
0
votes
0answers
68 views

Displaying Single Future Posts in a specific Category or Taxonomy

I want posts that are tagged with a certain term and scheduled to be posted some time in the future to be publicly available. So if I create a post, assign it a special term (category, tag, custom ...
0
votes
0answers
102 views

Using WP_Query IN pre_get_posts while searching

This is a continuation on this question. What I'm trying to do, is rerun a search query, to loop through it and index the taxonomy counts (so I can make some kind of facet search). What I do is this ...
0
votes
2answers
188 views

Remove category from query (show all posts in archive.php) pre_get_posts()

I am using pre_get_posts() to allow all posts to be displayed on any category archive. This is because I will provide a javascript sorting and filtering method using isotope.js. Any category page will ...
0
votes
1answer
54 views

How do I sort post listing by child post count?

I have two custom post types called questions and answers. The questions list includes a custom column which displays a count of the answers for each question. I need to be able to sort the listing ...
0
votes
2answers
209 views

Replace Main Query With Custom Query

I want to replace the main query with my own custom query. The thing is I don't want to go through the hassle of manual paging. I know there's a filter posts_results but I'm not sure how to use it ...
0
votes
1answer
269 views

Can't sort order of wp_query with 2 meta keys

I'm trying to display custom post types by excluding the sold ones but also by displaying them in alphabetical order from the county meta_key. I'm trying to use pre_get_posts but I'm not sure that ...
0
votes
1answer
47 views

Wordpress filter function using query modifications

I'm trying to build a filter function for the main query on a custom post type archive page. The custom post type is named "Hotel". For this custom post type i have a custom taxonomy named ...
0
votes
1answer
146 views

Looking for a way to exclude frontpage and nav menu from query filter

maybe I'm thinking about this the wrong way, but I need to: A) exclude posts in queries site-wide (minus frontpage and navbar) based on a comparison with a meta_value, and B) orderby a differnt ...
0
votes
3answers
197 views

pre_get_posts redirecting

Is there any possibility to redirect visitors to home page, for example, if they aren't allowed to view page's/post's content, using pre_get_posts action? I'm trying to develop a simplified ...
1
vote
2answers
869 views

WP_Query orderby post__in remains ineffective in the Loop [closed]

I’m trying to query a custom array of posts for the homepage, trying to maintain the order given in the array. To a certain degree this works fine, WordPress finds the posts, but in the Loop the order ...
0
votes
1answer
710 views

How to pass custom parameter to WP_Query for filtering in pre_get_posts

I have an ajax request that returns the result of a WP_Query loop. I would like to detect in pre_get_posts filter the specific wp_query instance that is used in the ajax handler. I thought placing ...
4
votes
1answer
1k views

Changing the meta_query of the main query based on custom query_vars and using pre_get_posts

I've registered custom rewrite rules and query_vars to use for displaying a list of events based on ISO date format. For example when a user requests the URL, http://site.com/by-date/2013-04-04/, my ...
0
votes
1answer
48 views

Avoiding page loop

I'm doing a custom page that has multiple wp query calls, the thing is that I don't need the main query that is I don't need anything from the page contents, so in order to save load time I was ...
0
votes
1answer
311 views

Custom post types loop on a page template

Hi I'm trying to make a page template that shows a list of a custom post type ordered by a meta key, I easily made it with query_posts but I am trying to do it via pre_get_posts so I made a function ...
1
vote
1answer
318 views

Pre_get_posts Gives 404 on Custom Post Type

I'm trying to filter the query on a sub page called "Ask Question" to list all of the recent questions submitted by users, but I get a 404 when going to the page. Flushing the permalink structure did ...
3
votes
1answer
595 views

Using is_main_query to select custom post type on certain page

I've been trying to implement some of the ideas discussed by Andrew Nacin http://wordpress.tv/2012/06/15/andrew-nacin-wp_query/ into my workflow, specifically trying to move away from using ...
1
vote
1answer
357 views

Recommended way to drop a pending query (in pre_get_posts)?

It looks like an e-commerce plugin's core query will be of no use to me in one particular template so I would like to discard it completely in favor of my own WP_Query loops in the template. It's not ...
2
votes
1answer
112 views

When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?

This question is a follow up to a question I recently asked. I've implemented what seemed to be the only solution, and it seems to work (YAY!). I just need to verify that: This is really the only ...
6
votes
2answers
1k views

What is “main query”? [duplicate]

Possible Duplicate: How to know which one is the main query? I'm curious to know what is the so called "main query"? What I have is two queries on front page. if (have_posts()) : while ...
16
votes
3answers
2k views

Should I use Pre Get Posts or WP_Query

I have the following query which I call in my taxonomy.php template via query_brands_geo('dealers', 'publish', '1', $taxtype, $geo, $brands); This function works perfectly. However after reading ...
1
vote
1answer
181 views

Custom Order in WP Query

I'm trying to implement my own query ordering, here is what I came up with... $query = new WP_Query('post_type=contentboxes&include=' . $contentboxes . '&order=ASC&orderby=include' ); ...
1
vote
2answers
508 views

Single page theme that uses pages for the content

I'm making a one page site. On the page I want to run WP_Query three or four times to pull in those 3-4 pages. The page looks a bit like this: <div class="row"> <?php $args = array( ...
0
votes
2answers
3k views

Multiple orderby parameters in pre_get_posts() action

Referencing @Otto's response to a question I also had about ordering by multiple fields, here is what he said: Can't do it with a naive WP_Query. Use the posts_orderby filter to add your own ...
0
votes
2answers
504 views

How to apply pre_get_posts to a custom query?

How can I apply pre_get_posts to a custom query? For example, if I have: $custom_query = new WP_Query(...) //code here How can I apply the pre_get_posts for this $custom_query?
2
votes
2answers
294 views

Splitting the main query in multiple loops with query_posts and/or pre_get_posts?

I have a custom post type 'events', to which I have associated a custom taxonomy 'calendar'. The calendar has 12 fixed terms, for each month of the year ( 'august', 'october', 'november, etc.). I'm ...
0
votes
2answers
900 views

How Do I Use WP_Query to Run This Database Query as Search Result?

I have created a search box with a drop down box of 4 options to customize the search: A general default search, no filter A custom search according to the post title for a custom post type only. A ...
3
votes
2answers
182 views

How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?

I added the following to my functions.php: add_action('pre_get_posts', 'keyl_get_emp_posts'); function keyl_get_emp_posts($query) { if ($query->is_main_query()) ...
0
votes
3answers
3k views

Query with pre_get_posts to get pagination

After pretty much getting everything working with query_posts, I noticed my pagination wasn't running. I was told pre_get_posts should be the solution. My problems: I don't know how to pass all my ...
11
votes
2answers
2k views

Using pre_get_posts with WP_Query

I was reading Stephen Harris's excellent answer to this question regarding the use of WP_query(), query_posts() and pre_get_posts. He says "pre_get_posts is a filter, for altering any query. It is ...
0
votes
2answers
755 views

using pre_get_posts for search results not found

function hotlinkers_wp_query($query) { if ( !$query->is_admin && $query->is_search) { $search_query = str_replace('-',' ', $query->query_vars['s']); ...
73
votes
3answers
44k views

When to use WP_query(), query_posts() and pre_get_posts

I read @nacin's You don't know Query yesterday and was sent down a bit of a querying rabbit hole. Before yesterday, I was (wrongly) using query_posts() for all my querying needs. Now I'm a little bit ...
4
votes
1answer
509 views

How-to exclude terms from the main query the most performant way?

This Q is a follow up to this answer on the Q: "How to exclude a specific term for the search?". 4 ways to filter out posts that have a specific term Type | Pro | ...
2
votes
2answers
1k views

“pre_get_posts” firing on every query

How can I change arguments for the main query only, and not affect other queries? add_filter('pre_get_posts', 'custom_post_count'); function custom_post_count($query){ ...
3
votes
3answers
2k views

Archive Listings Filtered by Date Values in a Custom Field/Post Meta?

(Moderator's Note: The original title was "using archive by date with a custom date") I'm adding an additional date to posts as a custom field. Now I want the archive to show posts by the custom date ...