Questions tagged [wp-query]

"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 global variable that holds the main query object prepared by WordPress based on a given request.

Filter by
Sorted by
Tagged with
0 votes
2 answers
2k views

Query Posts (post meta)

my situation: I have a frontpage which filters 12 thumbnails out of 24 (each thumbnail represents a post's featured image), and displays them. The user has the ability to hide whichever post he wants ...
cr0z3r's user avatar
  • 316
7 votes
2 answers
7k views

meta_query: using BETWEEN with floats and/or casting to DECIMAL

Each post has a lat/lng value attached to it via postmeta. I'm trying to grab all posts within a bounding lat/lng value. Here's the get_posts query: $posts = get_posts(array( 'posts_per_page' =&...
Kevin's user avatar
  • 299
3 votes
3 answers
3k 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 ...
Industrial Themes's user avatar
3 votes
3 answers
31k views

How to limit the posts

I have a new question, how can I limit the amount of posts coming out of this query? I only need 7 <?php $newsposts = new WP_Query('cat=restaurant'); if ( is_front_page()) { echo '<h3 ...
brett's user avatar
  • 97
4 votes
2 answers
6k views

query_posts() in function makes global $wp_query out of sync?

This has me stumped for a while already. Either I am missing something very obvious or something very not obvious. I am also not entirely sure if this has something to do with WP or purely PHP ...
Rarst's user avatar
  • 99.6k
5 votes
1 answer
7k views

Search multiple custom fields by using meta_query

I'm trying to create a search results listing for a custom post type and the problem I'm running in to is with the way the 'meta_query' parameter is stringing the passed values together. It appears ...
hereswhatidid's user avatar
1 vote
2 answers
17k views

How do I get the title of a category in a custom loop?

I am using the following code to display a list of posts within a category, but I want to display the title in it's own h2 tag above the list. <ul class="subcats-list"> <?php $weightloss = ...
chris_s's user avatar
  • 319
61 votes
6 answers
200k views

How to Get All Posts with any post status?

I am creating a front end dashboard where I need to show all the posts by the current user. So, I need to show posts in all states, mainly published, trashed and the pending. I am now using a simple ...
Sisir's user avatar
  • 7,782
4 votes
3 answers
12k views

insert data in database table from plugin with WP3.1

I am quite new in WP Plugin World. I am trying to develop a plugin in WP 3.1 when I am trying to insert data into my table named "wp_enam" in the following way: $wpdb->insert($wpdb->enam, array(...
enam's user avatar
  • 827
3 votes
1 answer
213 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 ...
inwpitrust's user avatar
3 votes
2 answers
4k 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 ...
hsatterwhite's user avatar
1 vote
2 answers
3k views

Wordpress Orderby Numeric Value Not Working

I am trying to get all products from the wpsc-product post type and then display them by a custom meta field called release_date_year. However, it doesn't appear to be ordering my posts by this custom ...
Dwayne Charrington's user avatar
0 votes
1 answer
553 views

Prioritising and Ordering Posts By Category Name Using A Custom Loop

I have a custom loop pulling out videos all assigned to various categories. However there is a category called "new-video" and I need to pull out all videos using my custom loop, but I would like the ...
Dwayne Charrington's user avatar
0 votes
1 answer
113 views

Find Posts based on Child Post value

I am creating a plugin that adds two custom post types, one of which will always be a child of the other. The parent post type is for Events, the child for Performances. Before entering the Loop, I'd ...
saalon's user avatar
  • 180
1 vote
1 answer
1k views

Order query by meta_value with multiple custom fields

I would like to get ordered all my posts with multiple cutom fields (WordPress 3). Exemple, I've 2 custom couple meta_key/meta_value : " order_submenuexpositions / numeric " " ...
user avatar
0 votes
1 answer
338 views

Display agents (custom post type) alphabetically, except one who always shows last

I would like to display all agents a-z, except there is one agent who should always show up last. Ideally I'd like the ordering to be done from the value of a custom field, dName. I was looking ...
Chuck's user avatar
  • 523
0 votes
1 answer
1k views

empty WP_Query object on local install

I just realized, that i got a complete *empty WP_Query object* on my plain wordpress install. I reseted the DB, deactivated all plugins and activated TwentyTen as theme, but the complete Object simply ...
kaiser's user avatar
  • 50.6k
2 votes
1 answer
774 views

Page queried instead of a custom taxonomy

When I try to get an archive for a custom taxonomy, WP searches for a page and doesn’t find anything. The Setup My code from the functions.php: add_action( 'init', 'register_store_taxonomy' ); ...
fuxia's user avatar
  • 107k
0 votes
1 answer
199 views

Where is this query?

This query given below appears alot in my slow-query log. Can someone please tell me where can I find this query ? that will help me try to modify it SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM ...
Umair Jabbar's user avatar
0 votes
1 answer
589 views

Using wp_list_pages() after calling query_posts()

It's possible that I'm just doing this wrong, so feel free to let me know how you would solve this problem. I have a mostly page-based site, but there are a few "pages" where my content is coming ...
Gavin Anderegg's user avatar
1 vote
3 answers
6k views

how to group custom post type posts by custom taxonomy terms

I would really appreciate if you could help me :) I'm very stuck and don't know how to proceed. I have a custom post type called event and 2 custom taxonomies registered for it: event_type with tag-...
dashaluna's user avatar
  • 2,072
1 vote
2 answers
1k views

How to echo data after a WP_Query

I would like to display data from a post that has custom fields in a metabox. One of the fields is the URL for an image. How do I create an echo to display the image? The other field I want to call ...
user avatar
0 votes
1 answer
143 views

Is there something wrong w/ this code?

<?php $rp = new WP_Query(array( 'post_type' => array( 'post','videos','projects' ), 'orderby' => 'date&order=DESC', 'posts_per_page' => 4 )); while ($rp->...
jwp's user avatar
  • 169
28 votes
6 answers
56k views

How do I exclude a custom taxonomy from the post loop

Is there a simple or easy way to exclude all posts from a custom taxonomy in the loop? I've been looking high and low, and neither SE, SO or Google seem to have a straight answer. I know it can be ...
Thomas's user avatar
  • 487
2 votes
3 answers
2k views

How to get the parent's taxonomy?

I have 2 customs post type : "Artist" and "Concert", the "Concert" custom post type is the child of the "Artist" custom post type, the "Artist" custom post type has a "genre" taxonomy. What I'm ...
inwpitrust's user avatar
0 votes
2 answers
1k views

Custom Post Type 'Event': Chronological list of recurring events from meta_values in array

i have a custom post type 'events'. Each event (post) can have multiple dates. The dates (date, time, location) are stored as array. I need a query that creates a chronological list of all events from ...
Christoph's user avatar
  • 282
0 votes
1 answer
37 views

Is there a (preferable built-in) way to check what custom queries are used in a theme?

I've build a theme using custom post-types with queries like $my_custom_post_type_query = new WP_Query( array( 'my_arg' => 'value' )); Now I'm writing a plugin where I need to do something like $...
user avatar
1 vote
1 answer
152 views

Page displays content from different query?

How can I reset all variables in order to get the actual page content? I keep getting the last post's content I've called from a news-box I've implemented - but need the actual page's content .. ...
Fuxi's user avatar
  • 769
51 votes
10 answers
112k views

How to only display posts whose meta_value field is not empty?

Three people have already tried to solve this, and we're coming up nil. I want to show only posts that have a value in the meta_key 'featured_image'. So... if 'featured_image' is not empty, show the ...
robalan's user avatar
  • 747
1 vote
2 answers
4k views

WordPress documentation - WP_Query arguments

I've been looking for a list all WP_Query arguments. This looks obvious, but http://codex.wordpress.org/Function_Reference/WP_Query isn't helpful at all, "post_type" is mentioned only in an example, ...
Wordpressor's user avatar
  • 5,041
3 votes
2 answers
5k views

Sort posts alphabetically by custom field value, insert divider between different letters

i'm listing all posts of my custom post type "person" alphabetically sorted by the custom field last_name on a page. How would i insert a divider (e.g. an image of the letter) before a letter range ...
Christoph's user avatar
  • 282
3 votes
5 answers
18k views

Export wordpress table to excel

I have created PHP scripts before to export a database table to .xls format like this: $select = "SELECT * FROM tracking"; $export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) )...
Rob Bennet's user avatar
4 votes
1 answer
2k 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 ...
Christoph's user avatar
  • 282
2 votes
2 answers
13k views

Querying Multiple Custom Taxonomy Terms

I created a new taxonomy called 'country' and have two terms items inside it: 'USA' and 'Canada'. How do I go about querying this info? I have a filter page with two checkboxes: <input type="...
Norbert's user avatar
  • 141
11 votes
3 answers
20k views

Filter by one custom field, order by another?

I have a custom post type "Listing" and I want to get all Listings that have a custom field gateway_value != 'Yes', and order the results by another custom field, location_level1_value. I can get the ...
gillespieza's user avatar
  • 1,275
2 votes
3 answers
3k views

How to find if a post with custom_field == X exists?

I need to find if a post with a custom field X equal to Y exists in a wordpress installation. Should I do it with a simple sql query or is there something build in that can help me achieve it?
user avatar
0 votes
2 answers
559 views

How to create query to get top 3 sticky/latest posts

I hope I will make sense, and if you have a better suggestion please let me know. I am just starting WordPress I want to layout my theme such that I get 3 sticky, not more than 1 month old, or latest ...
Jiew Meng's user avatar
  • 1,921
0 votes
2 answers
187 views

Is there ANYTHING about this query that's incompatible with WordPress 2.9.2?

I've been puzzling over this one for two days. Still can't figure it out. I'm testing a theme release in multiple versions of WordPress using xampplite on localhost on a PC. I'm having a problem on ...
Scott B's user avatar
  • 5,666
1 vote
2 answers
2k views

"Apache HTTP Service has stopped working" with WP Query in WordPress 2.9.2

When my script runs the 4th line below in WP 2.9.2, its causing my web app to throw an "Apache HTTP Service has stopped working" error $cat=get_cat_ID('top-menu'); $catHidden=get_cat_ID('hidden'); $...
Scott B's user avatar
  • 5,666
2 votes
2 answers
1k views

Sorting posts DESC based on the number of comments using WP_Query

I have this unusual requirement from my client that I need to accommodate. They want to be able to view the posts with the largest number of comments first. At first I thought using a custom select ...
PFrank's user avatar
  • 121
1 vote
1 answer
2k views

Custom Post Type Loop within Shortcode

I'm really at loss as to why this isn't working: I am using a shortcode to display a query on a custom post type + taxonomy, this is the segment of it: // - arguments - $args = array(...
Noel Tock's user avatar
  • 881
17 votes
1 answer
26k views

Passing and retrieving query vars in wordpress

I have two authors pages, one displays about 5 posts. Then I'm trying to setup another page that will be all of their posts. I have created a template called moreauthorposts.php and I'm trying to ...
codeisforeva's user avatar
28 votes
4 answers
17k views

Is it necessary to use wp_reset_query() in a WP_Query call?

I'm using the following code to retrieve posts: <?php $featuredPosts = new WP_Query(); $featuredPosts->query('showposts=5&cat=3'); while ($featuredPosts->have_posts()) : $featuredPosts-&...
wyc's user avatar
  • 3,857
3 votes
1 answer
2k views

Is it better practice to use query_posts, WP_Query, or get_posts to create various custom loops within a Page?

Right now, I'm using get_posts to retrieve cusstom posts types with a custom taxonomy assigned to it in order to generate static content like this: <?php /** * Template Name: Front Page * @...
wyc's user avatar
  • 3,857
4 votes
2 answers
5k views

Pagination with WP_Query is buggy - working for some pages, but not the others

I'm having a very peculiar bug with pagination :( I'm trying to display 4 posts per page for a category with slug "lastest-news". The pagination function seems to work correctly. There are 33 posts. ...
dashaluna's user avatar
  • 2,072
1 vote
2 answers
10k views

How do I change the order (ASC and DESC) in the following retrieval method using WP_Query?

The following code retrieves only custom post types with the custom taxonomy "Slider." I would like to change their order to ASC. The code: <?php // Retrive custom post type with a custom ...
wyc's user avatar
  • 3,857
0 votes
1 answer
785 views

Display different number of posts from one category on the different pages

according with Pagination with custom loop. I use the custom loop for display flash game. For make a pagination on the page with posts from one category (mydomain/category/categoryName) I used: ...
glazsasha's user avatar
  • 101
0 votes
1 answer
3k views

Ajax future single post query doesn't work when NOT logged in

I am having a problem with an ajax request for a single post, when the user is not logged in. The post is a calendar date and is in the future. the query works fine if I am logged into wordpress but ...
Thomas's user avatar
  • 13
0 votes
1 answer
7k views

How to include category name/id in wp_query for retrieving "custom post type" from a particular category?

Here is the code I'm using right now. It fetches the posts from all the categories in the 'sp_events' post type. <?php $feat_art = new WP_Query(array('post_type' => 'sp_events','post_status' =&...
Sri's user avatar
  • 33
0 votes
1 answer
1k views

Sorting the Loop by Taxonomy Value

This is a similar question to Sorting for each custom taxonomy, but I don't feel like it was clearly asked or responded to. I have a custom post type "player" and a custom taxonomy "player_details". ...
Derek Perkins's user avatar