"wp-query" ambiguously refers to one of two things. 1) WP_Query is a class native to Wordpress which allows users to query the posts database using a number of criteria. 2) $wp_query is the default object that holds the main query object on each WordPress page.

learn more… | top users | synonyms

3
votes
1answer
264 views

Sanitation needed for WP_Query or get_posts calls?

Just wanted to get a straight answer on this: when submitting query_vars to a call to get_posts or WP_Query, is sanitation needed or does WordPress already take care of that?
3
votes
2answers
249 views

Identify which loop you are hooking into; primary or secondary?

What is the most efficient way to determine which loop I'm in? I have a few plugins that alter the query by hooking into various parts of WP_Query::get_posts(), through the usual suspects, ie ...
3
votes
3answers
64 views

Display posts the match taxonomy term linked from wp_list_categoies?

This should be simple, but it escapes me. I have a custom post type and a custom taxonomy. The taxonomy is named "asset_type" and the slug is "type" I am using wp_list_categories to provide a ...
3
votes
1answer
125 views

Is it true $wpdb->get_results is faster than WP_Query in most cases?

On my homepage, I have a section where I have to display the last five featured posts, where a featured post is simply a post with a custom field is_featured set to 1. I achieved what I want with two ...
3
votes
1answer
115 views

How to stop wordpress to make the default query?

My goal is a redirect to a custom template based on some new rewrite rule, but without having wordpress to make unusefull queries. my code: function add_rewrite_rules() { add_rewrite_rule( ...
3
votes
1answer
397 views

Order posts by ID in the given order

In the back-office of my theme, the users can choose which posts to display in the front page, and they can also choose in which order the selected posts should appear. I have tried like this: ...
3
votes
1answer
312 views

How to Access Global $multipage or Global $numpages outside the loop?

I am writing a code in the header that pertains to link rel='prev' and link rel='next' thing but I need to check if the post is multipage. I check out these global variables: $numpages $multipage ...
3
votes
1answer
2k views

Merging multiple wp_query objects

I have the code below for a multisite install. It works fine, but I need to merge each WP_Query loop object from each multisite together for use in another template with the WordPress loop. Is this ...
3
votes
1answer
3k views

Warning: urlencode() expects parameter 1 to be string, array given

I have posted a question on StackOverflow (sorry for the cross link) and while I'm striving to find a solution to this, I stumbled across this warning : Warning: urlencode() expects parameter 1 to ...
3
votes
1answer
3k views

Meta Query with AND & OR?

I'm trying to do some filtering for some posts in WP_Query, but I can't seem to get the right condition. Basically what I wanna do, is get posts that have the custom field event_data (sorted by this ...
3
votes
1answer
2k views

WP_Query with checkbox meta_query

I have posted this on StackOverflow too, not sure if that's allowed - if not let me know and I'll remove one (I don't want to look like I'm spamming). Anyway.... I have a custom post type and have ...
3
votes
3answers
2k views

How do I order by multiple custom fields using wp_query?

I have a rating system where the user can enter a custom field of either "Stars" or "Hearts", but whichever one they choose they have to enter a value of 1 thru 5. Using wp_query, I can successfully ...
3
votes
1answer
185 views

How to make an activities stream mixing posts and comments?

What I'm currently trying to make is an activities stream wich list : The posts, the comments, both mixed between them and ordered by date. My idea is to make two queries, but i don't know how to ...
3
votes
1answer
36 views

WP_query taxonomy + get all posts with two terms from same taxonomy

This is a follow up question to Add_query_arg + two times the same argument? I want to get the post count from all posts tagged with 2 different tags from same taxonomy $args2 = array( ...
3
votes
2answers
88 views

“pagination” (but not really) and queries using custom posts types

More of a conceptual question here, than a strict code question: Working on a site for a musician who wants to list concerts, both upcoming and past. These are custom post types that use a custom ...
3
votes
1answer
520 views

How to make a WP_Query search with custom post types?

I've registered a custom post type called "node". When I create a basic WP_Query to get posts of that type, it works just fine. Example: $args = array( 'post_status' => 'publish', 'post_type' ...
3
votes
2answers
176 views

replace the WP_Query class in the main query

For a project I needed to heavily modify the behavior of WP_Query. So what I did was extending WP_Query basically like this: class eacf_shared_query extends \WP_Query { function query( $query ) ...
3
votes
1answer
317 views

switch_to_blog() performance considerations & alternatives

I'm currently in the conceptual phase for a multisite network. The rough idea is: There are multiple networked sites and all publish posts for their own. The network admin is able to establish ...
3
votes
1answer
164 views

How to query for a week using key => value WP_Query argument notation?

I would like to be able to query for a specific year and week using WP_Query argument notation. I am using this notation as I would like the page to paginate. What's the correct "year" and "week" ...
3
votes
1answer
691 views

Querying post from a multisite network

I am working on a multisite blog network where I have to display recent post on my home page, 10 post per page navigation. I did implement it using wpdb object with one complex sql statement. I got ...
3
votes
1answer
2k views

Get posts with tag all post types

I'm trying to get all posts that have a specific tag, regardless of what type of post that is. I've tried every solution I've found (here on SO and further), but nothing works: I always only get the ...
3
votes
2answers
2k views

Why is WP_Query not working with category_name?

Why on earth is this piece of code not working? $my_query = new WP_Query('category_name=feature'); while ($my_query->have_posts()) : $my_query->the_post(); echo 'test'; ...
3
votes
1answer
708 views

Display Posts by modifying the where clause only for my query

I am trying to display posts that are 7 days old. For that i need to modify the 'where' clause as in code //Hack found on the bottom of http://codex.wordpress.org/Template_Tags/query_posts ...
3
votes
1answer
572 views

Want to redirect if search query match exact title of any post

I am using WordPress 3.3.1 and new to this system. I want to redirect the search query to the post if query exactly matches post title of some post. I also want it to run before any search query ...
3
votes
1answer
1k views

Custom Post Type “Event”: chronological list of recurring events

i'm looking for a good and easy way to have a custom post type "event" that can have multiple dates. (I have tested about 20 plugins). I think i have no problem building a metabox allowing the user to ...
3
votes
2answers
73 views

Adding Post Counts to Menu (Nav) Programmatically?

I'm fairly stumped on this. Without getting too query-heavy, I was wondering what path one might take to produce a menu that links to a category of posts, and displays in parenthesis how many new ...
3
votes
2answers
113 views

Query meta field using between

I'm trying to Query some lattitude and logitude and then I get some long numbers and apperently the Query dont like that. Let says I have these in the database Meta-key: lat Meta-value: 54.3415000 ...
3
votes
1answer
555 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 ...
3
votes
1answer
277 views

get data from wp-query, outside the loop & without url change

I am working on an advanced search on wordpress based on custom taxonomies. I've been stuck for 72h so I was hoping to have some help or thought... Step 1 --- in the js file the query strings are ...
3
votes
1answer
283 views

get_query_var() not working in pre_get_posts

I'm using the pre_get_posts hook to order the main query on all my custom post type / taxonomy pages using a custom meta value. As part of the logic, I am trying to determine which taxonomy is ...
3
votes
1answer
121 views

Excluding posts from a category but only if they're not in multiple categories

I am looking to exclude a category in Wordpress. I am referring to the Wordpress Codex page on wp_query but I am having the following problem: I want to exclude posts from category 1, but if a post ...
3
votes
1answer
526 views

Limit search results to exact match

I have a problem showing results in Wordpress with WP_Query. Problem is simple but as far I'm not programer I wound it difficult. So, I have custom field with values like 1-1-1-1 and 2-1-1-1-1 for ...
3
votes
1answer
148 views

BP Multi Network & Members Directory [closed]

With bp-multi-network it appears members are shared across all networks. Example - networks based on location. newyork.mydomain.com, losangeles.mydomain.com, vancouver.mydomain.com At present a ...
3
votes
2answers
214 views

Order Posts by Closest Numeric Values

I'm using custom post types to display properties and have a custom price field assigned to each post. On the property page I want to display a list of four similarly priced properties, two less than ...
3
votes
2answers
425 views

What could be causing my wp_query pagination to break?

I'm using categories and wp_query to create an "advanced search" feature on my website. It was working great until recently I noticed that the pagination was broken. The following 2 links should ...
3
votes
1answer
265 views

Query two taxonomies via URL or link?

I've been banging my head about this, and have created a work-around, but it would be much nicer for my site's organisation if I could figure this out. I want to be able to query posts across two ...
3
votes
1answer
964 views

Is it possible to wrap Geo Location search around WP_Query?

I'll just like to add that I have a current working solution in place and works well but I'm looking for ideas of being able to do it better or cleaner if possible. We have hundreds of properties in ...
3
votes
1answer
146 views

Search widget breaks when using multiple loops?

I have created wordpress template that uses two loops via WP_Query object. Everything works fine except Search widget. I've been pulling my hairs out for three days now Googling like a madman,but ...
3
votes
2answers
176 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()) ...
2
votes
2answers
3k views

WP_Query and next_posts_link

I cannot figure out how to make next_posts_link() work within my custom WP_Query. Here is the function: function artists() { echo '<div id="artists">'; $args = array( 'post_type' => ...
2
votes
3answers
5k views

Pagination with custom SQL query

I have my own SQL string to select Custom Post Type posts with specific WHERE clause. I've used the offset and limit to return appropriate posts depending on a page being displayed. That's working ...
2
votes
1answer
6k views

How to get an array of post data from wp_query result?

When run a query with WP_Query method, I got an object. I understand that I can then do the loop to display stuffs. But, my goal is not to display anything, instead, I want to get some post data by ...
2
votes
3answers
4k views

paginate_links() adds empty href to first page and previous link

This is really weird. In attempting to solve this problem i ended up with an almost perfect use of paginate_links() instead of a custom pagination function: $myquery = new WP_Query($args); $paged = ...
2
votes
2answers
3k views

Displaying Posts Related to Other Posts by a Taxonomy Term?

I have a custom post type for musician's profiles, and a taxonomy for their location (categorised hierachically into Countries and then Cities). On the musician's individual profile pages I need to ...
2
votes
1answer
5k views

“tax_query” parameter not working with WP_Query

I have a custom post type called 'episode'. Attached to 'episode' I have a custom taxonomy called 'video_type' that contains two terms: "bonus-footage" and "episode"; "episode" contains two child ...
2
votes
1answer
619 views

WP_Query() show posts that end later than today

I have a query as follows: $wp_query = new WP_Query( 'meta_key' => 'end_date', 'meta_value' => 'today', 'meta_compare' => '>=', 'post_type' => 'vehicle' ); ...
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){ ...
2
votes
2answers
3k views

Using a custom WP_Query with get_template_part loop

I have a query for a custom post type: <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $books = new WP_Query(array( 'post_type' => 'wiki', 'posts_per_page' => ...
2
votes
2answers
1k views

How to trigger 404 for custom query var?

How can you trigger a 404 when using custom query vars? I've got re-write rules written for a custom query var, but if you were to request a URL for the query var that should technically be a 404 it ...
2
votes
2answers
3k views

Next_posts_link() works only with original $wp_query

I've got custom template that I want to display paged blog posts. This is the beginning of my file: $wp_query = new WP_Query($args); if($wp_query->have_posts()){ ...