"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

0
votes
1answer
16 views

Is there any difference between below WP_Query code snippets?

Below code return the same results. Is it any difference between them and if it is then which one is better? code snippet 1: $args = array( 'post_type' => 'product', 'meta_key' => ...
0
votes
0answers
17 views

What's the easiest way to update one taxonomy term after searching for another connected with the same post?

What's the best or easiest way to: Write to one custom taxonomy term ("registereddonation") value when given another custom taxonomy term ("dbtoken") value which is connected with the same custom ...
0
votes
0answers
30 views

Get closest event where meta_key field is an array

I have a custom post type called "Event", which contains a repeatable date field _cmb2_date . I have a function which prints out posts: function post_style_6($args) { global $post; $the_query ...
0
votes
1answer
18 views

WPDB for post count on post

I figured out how to show the count of a custom post type on author.php . I am trying to display the stats on their custom post as well. The same query does not work. How can I show the amount of ...
0
votes
2answers
43 views

Get meta info related to current post

I'm trying to get the meta info by key rw_related_link for each post but my code is wrong since instead get the ones related to the current post I got the same in all post and that's wrong. This is ...
1
vote
1answer
68 views

How to order a post type with meta_value_num and if meta_value_num does not exist then order by date

I want to order a list of post on basis of ratings. I have used meta key "wp_ratings" for storing the rating value in wp_postmeta table. Now I want to sort all posts . If a post does not contains the ...
0
votes
0answers
32 views

wp_query - Modify $query to include duplicate content

I'm setting some featured content through the customizer (it's saved in theme_mod); Using the pre_get_posts hook, I'm retireving the feature pages in this way: ...
3
votes
2answers
117 views

Return only Count from a wp_query request?

Is it possible with the standard build-in tools in Wordpress to get wp_query to only return the count of an query? Right now, I’ve a query which has several meta_queries but what the only thing I’m ...
0
votes
1answer
206 views

Pagination in WP query with transient API

I have integrated WordPress transient system with w3 total cache. Now I can`t to do pagination for this query. <?php $paged1 = (get_query_var('paged1')) ? ...
0
votes
1answer
42 views

add_query_arg to compare and display events from a certain date

I have archive-events.php file that sorts custom post type 'events' via WP_Query using custom field that is date formatted YYYYMMDD (20150215) like this: $args = array( 'post_type' => ...
0
votes
0answers
26 views

Adding a Theme Customizer Control for Posts_Per_Page

I am trying to add a Theme Customizer Control to change the number of posts shown in my WP_Query posts_per_page, like so... <?php $posts_per_page_option = get_option( 'posts_per_page_option' ); ...
0
votes
1answer
59 views

Trying to get property of non-object in: $wp_query

I've this function at functions.php file: function custom_secondary_nav( $menu_name, $id = '', $menu_title = '' ) { global $wp_query; // others stuff goes here if ...
0
votes
0answers
31 views

how to get post by metabox in wp_query

I want to WP_query by tag_id but i need to insert tag_id by metabox i cant do it and give wrong any one help me? $value = get_post_meta( $post->ID, '_my_meta_value_key', true ); <?php ...
1
vote
1answer
70 views

How to prevent writing duplicate loops?

So i have some pages where i want to show my custom post type 'events' only by the last 5 posts (secondary query: WP_Query object) and some pages where i want to show all posts (for instance archive ...
0
votes
1answer
55 views

Can't get the_content to show

I'm using the following code to get posts from a category in a page. This category uses ACF for some fields. However, when I try to output everything, it shows everything but the_content. For better ...
0
votes
1answer
24 views

Add filter to Orderby Parameter using Array

Using WP-Query, I'm setting the Orderby parameter using an array: $events_args = array( 'post_status' => 'publish', 'post_type' => 'events', 'meta_key' => 'start_time', ...
80
votes
4answers
56k 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 ...
1
vote
1answer
76 views

convert custom query to wp_query

I have used classipress theme My query is as below $querydetails = " SELECT wposts.* FROM $wpdb->posts wposts INNER JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id ...
5
votes
6answers
12k views

Display all posts in a custom post type, grouped by a custom taxonomy

I’m working on a member page where I use a custom post type with a custom taxonomy. My custom post type is called “member” and my custom taxonomy is called “member_groups”. I want to list all the ...
1
vote
2answers
2k views

Conditional arguments WP_Query for post custom fields

All in my case I want to get post result by Gender, Age, City etc... I am using this query. If i have any of variable like age, city, gender for that "AND" operation will perform and get only result ...
0
votes
2answers
61 views

Why does WP_Query have methods that return public properties of the same name

Most of (if not all) the is_* methods in the WP_Query class have a matching public property and the methods appear to just return the property e.g: public function is_search() { return (bool) ...
1
vote
4answers
2k views

Get count of custom post type created by current user

I'm trying to get the count of published posts in a custom post type for the current user (to display on a profile page). I found this here on the forums: <?php global $wp_query; $curauth = ...
3
votes
3answers
138 views

Query posts distinct authors

I am trying to get post from a category ordered random, but making sure that the author does not repeat itself. So I have this query which works as intended, but there is the chance that the author ...
0
votes
0answers
45 views

Both WP_Query and get_posts returning 1 post

I am having a weird issue. Both WP_Query and get_posts returning only one result, i.e only the latest post. Never faced this before.. The WP_Query: function custom_tsr_query() { $the_query = ...
0
votes
1answer
43 views

How to get rid of extra Untitled Article in html5 document outline when using new WP_Query?

Here is a simplified version of the code I'm using on a static homepage template made for a child theme of TwentyTwelve. I simplified some of the divs used for styling and just focused on the problem ...
0
votes
1answer
34 views

Query Set Order By Author

I am attempting to orderby the author_name when you click on the Author arrow on a list of tickets. When you click the arrow, the names are ordering by something I cannot identify. I want them to ...
0
votes
1answer
52 views

Loop with Custom Post Type and Taxonomies

Regards, i've a problem. What i want: Show a toggle with loop from Custom Post Type I create post type: Episodio And a Taxonomy: Temporada I create this loop: <?php $post_type = ...
0
votes
0answers
41 views

2 loops with pagination on a single loop

On a page I want to always show the most recent post on top with a different layout, and have the rest of the posts listed below. So I created a template page with these 2 loops. But I cannot figure ...
-1
votes
2answers
117 views

Cannot exclude particular post from loop of custom post type

I have a custom post type (from a theme installed by previous developer), and here is the code of loop which retrieve the post and display them. <?php // Counter $post_count = 1; // Query ...
0
votes
2answers
54 views

Custom shortcode not displaying categories and correct date

I wrote a short code to work with an event plugin (the plugin creates the custom post type of event). I want to pull all future events from the database that use a specific category and list them on ...
0
votes
1answer
233 views

WooCommerce search products between price range using WP_Query

I am currently building my own custom advanced search functionality for a WordPress website with Woocommerce. You should be able to search using: Category Min/Max price My current progress is ...
0
votes
1answer
42 views

Custom search (wp query by custom fields)

I'm building custom search. Actually it's just need to check custom field value. The custom field is called 'summary'. However i'm not sure what i'm doing wrong as it is not working. Maybe someone ...
0
votes
1answer
73 views

WP_Query - using category__and when one of the categories is 0

I am passing a variable $category to category__and, and it works unless $category = 0; 'category__and' => array(4) // works 'category__and' => array($category, 4) // works if category > 1 ...
0
votes
1answer
70 views

WP_Query custom order and pagination

I am seeing some strange behaviour when combining a custom order with pagination when using WP_Query. The arguments for my query are as follows: $args = array( 'post_type' => 'news', ...
0
votes
2answers
65 views

Make a WP Query search match exactly the search term

I'm using WP Query and the results coming back when using the search term aren't working as I wish. For example searching for 'art' returns also results for words containing 'art' such as 'part'. How ...
0
votes
1answer
102 views

Pagination for custom query throws 404 errors on last pages [duplicate]

I'm using a custom query to get all CPT posts for the author in author.php. I have a lot of authors and a lot of content so I'm using the wp pagenavi plugin to paginate between these posts. For some ...
-1
votes
2answers
658 views

How to get Tags with specific post id

I have created one post and post ID is 34 and added some Tags and Now I want to retrieve all tags with post ID. Any Idea?
-1
votes
1answer
37 views

Adding css tweak based on page template

I have a parent page that is listing out all of it's child pages. This is done using the below: <?php $query = new ...
1
vote
1answer
4k views

Get current post id in functions.php

I have a wp_localize_script() function in my functions.php where I need to push the current post ID of the current post to a jQuery file. So I was wondering how you can get the current post ID of a ...
0
votes
1answer
61 views

modifying meta_query on parse_query

In the parse_query filter hook I'm doing: if ( is_admin() && $pagenow == 'edit.php' && isset( $_GET['ysr_homepage_filter'] ) && $_GET['ysr_homepage_filter'] == '1' ) { ...
0
votes
1answer
18 views

List of child pages fetch next results at link click

I have a list of child pages which are getting displayed as links to those pages. Im displaying it in a certain div with a maximum of 6 results. What I want is I have a "a href" which is called ...
4
votes
1answer
94 views

WP_Query by post ID doesn't work if post is in custom post_status

I want to display a single post by its ID using WP_Query(). To do this, I use the following argument: $args = array( 'p' => 61202); That should work, but does not seem to work if the post is ...
0
votes
0answers
16 views

Search results for author account pages

I'm looking to find out if there are any plugins / code out there for Wordpress search to return results for user author accounts. NOT posts from authors. NOT pages that authors have created, but the ...
0
votes
1answer
18 views

Display post from custom post type

I have this Custom Post Type (CPT) defined at functions.php: register_post_type( 'opinion', array( 'label' => __( 'Opiniones' ), 'singular_label' => __( ...
0
votes
1answer
212 views

Is there a function to get post info for any publish_status by post ID?

I'm trying to, essentially, check whether a post exists and if it does (in published, draft or auto-draft states) return the post info. I'm finding get_post() doesn't seem to work with drafts, and ...
0
votes
4answers
396 views

Sort users by meta_value_num

I'm having problems using WP_User_Query to sort users by a meta value number, I would of thought this would be simple by it just displays results as descending alphabetically. <?php $args = ...
0
votes
1answer
47 views

Order posts by custom column using pre_get_posts

Is it possible to sort posts by custom column in wp_posts table (in this case, 'fav_count' column) using pre_get_posts filter? If not, is there any other way to do this before the main query is run, ...
0
votes
0answers
31 views

How to stop wp_query searching pages as well as the specified CPT

I have a CPT that has multiple fields. I have a custom input form that takes a name as the input and this is stored in the $surname variable. I need to search my CPT for that name either as the CPT ...
0
votes
1answer
14 views

Display images with same specific value?

I'm trying to make a slider for my website, but I'm a little bit stuck right now. The thing is that I don't want to use any plugin (I prefer to try to learn how to do this, and also most plugins have ...
0
votes
1answer
48 views

More efficient way to list posts by category [duplicate]

I have a page that lists posts grouped by category. Here is the current code: <?php $cats = get_terms('category'); foreach ($cats as $cat) { $cat_id= $cat->term_id; echo ...