"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

1
vote
2answers
11k views

How to display page content in a page template?

In my WordPress site, I made a custom page template, which contained a custom query [using WP_Query()]. With that query, I can perfectly get the posts of a certain category. But I want to show the ...
0
votes
0answers
39 views

Custom Post Type: Event - Display Upcoming Events for Next 30 Days

I need to display the upcoming events for next 30 Days and sort the same based on custom date field. Below is the code I am using right now but not got any success in hiding old Events and ...
0
votes
1answer
28 views

Displaying Event within two given time frames

I'm trying to display two different posts from my CPT named Events. One is going to be the next event the other is going to be previous event. I've got a metabox called 'Event date' The client at ...
0
votes
0answers
52 views

wp_query display posts based on day

I am trying to get all posts to be displayed on a certain date. For example today Tuesday I want all posts to be displayed. It doesn't matter that the posts were created today (Tuesday) or last week ...
0
votes
0answers
36 views

When WP_Query only returns 1 post, how do I automatically redirect to that post?

I've been searching around for a few hours now and can't figure out how to do this. Seems really simple. I've seen lots of redundant examples on how to redirect to a single post when a search result ...
0
votes
1answer
77 views

Current post in AJAX call is always zero

I have a custom post type named event and a button to load more timeline. I need to arange current timeline item to the left or right depending on his current_post from WP_query object. Ex: if ...
0
votes
2answers
34 views

get_post_meta in WP_Query

I'm doing a plugin to add likes to posts I want to create a table on a page in the plugin to show each post and the number of likes function my_plugin_options() { echo '<p>Table of ...
0
votes
0answers
24 views

Integrating WP_Query with multiple Checkboxes

Ive created a CTP called volunteer_position_cpt ... I've also created two taxonomies for this CPT: volunteer_category (tags) and location_category (tags) My interface: [ ] Category 1 [ ] Category 2 ...
0
votes
1answer
63 views

How to show the posts of some category first, and then all other

How to show the posts of some category first, and then all other posts that does not belong to that category? I have logic that get the category and reorder the posts. But i don't know how to use. ...
0
votes
1answer
31 views

Unlimited Page Sitemap Link

I am trying to display all the product links (7000+) of woocommerce, but I get a blank result when doing so. When I set 'posts_per_page' to 2000, it returns a result. More than 2000 returns a blank ...
0
votes
1answer
34 views

Wordpress query portfolio posts

On my template I have this code <div class="blog_block"> <?php wp_reset_postdata(); ?> <?php $nbmax= 9; ?> <?php $tarali_query = new ...
0
votes
1answer
36 views

Slow getting posts from category

My blog has over 700,000 articles and my category structure as follows: -Cats Cat 1 (ID: 3) Cat 2 (ID: 4) Cat 3 (ID: 5) ... Cat 20 (ID: 22) I took the articles by using the following SQL ...
0
votes
1answer
56 views

Remove Post if Advanced Custom Field is checked to fix paging

I'm trying to setup a query that filters through posts and removes ones that have an ACF field "archived" checked. Post queries are pretty foreign to me. ...
0
votes
1answer
43 views

Pagination error Wordpress multiple loop

I have multiple loops using wp_query() in WordPress. I want to show the posts from first loop first (post per page=10), and if there are no posts from first loop show, then show the second loop. For ...
0
votes
2answers
71 views

Multiple wp_query loops showing first 5 posts on all pages instead of older posts[Resolved]

I am trying to highlight the newest post in a separate layout and rest of them in a masonry index. There are 5 posts per page and I am getting the newest 5 posts on previous posts pages as well. I ...
3
votes
2answers
472 views

How to prevent execution of default query, while preserving ability to use WP_Query in template?

PROBLEM: I'am trying to prevent execution of default WordPress query for custom category template. I have found a possible solution, but looks like it preventing execution of all post queries: ...
0
votes
2answers
347 views

Sort posts by category name and title

Trying to figure out how I can output my posts based on category title (a–z) and secondly, the title of the posts within the category: A CATEGORY – A post beginning with a – Because I want to be ...
0
votes
2answers
58 views

Display single most recent post in category on every page of category archive

I am trying to display a single "featured post" in the archive.php template using a custom query. This featured post should be the most recent post in that category or tag. I'm using pagination for ...
0
votes
2answers
32 views

Modify Search Query if original Query gave no results

I'm looking for a way to modify the search query if the performed query returned no results. Let's say I'm looking for "Opening times", so I go to this URL: http://mysite.com?s=Opening+times Now, ...
0
votes
2answers
118 views

Using DISTINCT in wp_query

I need to create a system where the user first selects the state, then select the city and then see the information of the stores in that city. For this, I created a cpt called store with 2 meta ...
-5
votes
1answer
43 views

custom sort posts in archive/taxanomy page

I want to override the default sort order of posts in archive and taxonomy pages. what hooks should I implement?
0
votes
2answers
2k views

Orderby menu_order doesn't work

My code is: $sliders = new WP_Query(array('post_type' => 'sliders', 'showposts' => '10', 'orderby' => 'menu_order', 'order' => 'ASC', 'countries'=> 'Default', 'supress_filters' => ...
0
votes
1answer
217 views

WP_Query breaks pagination

I've been on this problem for a week now. I've searched through countless posts that just aren't answering the question. It seems that my wp_query breaks pagination. I've looked through a lot of the ...
1
vote
1answer
75 views

How can I get an array of all IDs from the current queried object?

I am trying to join an array of post IDs together. Right now, it seems my code is creating a separate array for each ID, instead of one array with each ID. This is the code that I have come up with. ...
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 = ...
0
votes
1answer
36 views

Search Query that Includes Custom Table

I have a WordPress website that grabs product data from a custom table. I would like to be able to also search from fields in the custom table. Could someone provide a sample query of what this would ...
0
votes
1answer
46 views

How can I base a query off of the current page post type AND a meta value from another custom post type

I have 2 custom post types: Communities and Testimonials. I have a drop down menu in the Testimonials CPT that calls all of the communities. The drop down is using the ID of the community. I have ...
0
votes
0answers
41 views

Pagination on static Posts page

I'm having an issue with pagination on the static blog page. Under Settings > Reading, "Posts page" is set to a static page. "Blog pages show at most" is set to 10 posts. The first ten posts show up ...
1
vote
2answers
55 views

Multiple filter conditions for WP_Query

I'm having a hard time figuring out how to accomplish this (really simple) task: Get 4 random posts, but only select from the 10 most recent posts. This works great for the random part, but ...
0
votes
3answers
50 views

How to query posts for custom post type with featured image for first 2 post?

I am trying to write a custom post query for a specific post type in a way where only first 2 thumb/featured-image will be shown & other will be just title & other metadata (i.e the picture in ...
5
votes
5answers
9k 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 ...
0
votes
1answer
35 views

Proper way to run wp_query from inside a plugin

I am developing a plugin that needs to make a query of a custom post type and retrieve data and meta data from these posts. But anytime I run that query inside my plugin, no matter what admin new post ...
1
vote
0answers
376 views

How to order posts by meta_value and title

How do you order products in WooCommerce so that products are random, but at the same time featured products show first? Here is my code: $args = array( 'post_type' => 'product', ...
0
votes
0answers
52 views

Some images not being returned with wp_get_attachment_image

For some reason this code works on my local copy of a wordpress site but the live site is not working. // WP_Query arguments $args = array ( 'post_type' => 'post', ...
0
votes
2answers
76 views

Nested WP_Query breaking loop

I'm using WP_Query to get all pages without subpages. For each page I'm using again WP_Query to get all child pages of the current page inside the first loop. This all works fine and I'm getting the ...
1
vote
0answers
15 views

Querying multiple post types ensure 1 of each type [duplicate]

If I'm querying more than 1 post type, is it possible to ensure that I will always get at least 1 of each type? $args = array( 'post_type' => array( 'post', 'project' ), 'posts_per_page' ...
0
votes
0answers
57 views

Pagination with WP_Query not working

I have a custom page template on my site, with a WP_Query pulling in a list of posts. I'd like to implement pagination but just can't seem to get it right. Here's the code I'm using blelow, which ...
0
votes
1answer
29 views

check if a taxnomy queried in $wp_query?

Is there a way to check if there is any taxonomy that has been queried in the global $wp_query?
0
votes
0answers
4 views

How to remove a filter that has been added as a function [duplicate]

How can I remove a filter that has been added the following way: // Add the filter before executing the query add_filter('posts_where', function( $where ) use ( $lat, $lng) { return ...
1
vote
2answers
39 views

How to display summary content from a Page (Not a Post) on another page

I created a Page called "About Joe" as a page in WordPress. Then on a different page (e.g. the homepage), I wish to display a summary which includes: a thumbnail the 1st paragraph link to page ...
0
votes
1answer
333 views

How to display comments list by order when clicking on newest or oldest link?

0 down vote favorite I have a wordpress single post where I have comment system - Live Site And I have two links one is: 1. newest 2. oldest The thing I want is when I will click on newest it will ...
0
votes
2answers
455 views

How to sort queried pages by an array of page ids?

I'm creating a one page wordpress website, and I need my 'home', 'about', 'portfolio', 'services' and 'contact' pages to all be on my front page. I created the following page template for my front ...
0
votes
1answer
38 views

Sort posts by activity date

I have a list of posts posted on different dates I can order the posts by date $loop_args = array( 'post_type' => 'post', 'order_by' => 'date', 'order' => 'ASC' ) How can ...
0
votes
2answers
2k views

How to get only ONE category of “Portfolio” posts to display on main page rather than ALL categories?

I have a section on my main page that displays a new “Portfolio” post each time I write one no matter what category I assign them to. What I want to do is make the main page only display one specific ...
0
votes
0answers
29 views

Modify taxonomy-$taxonomy-$term.php to include posts from all blogs in multisite

How should I modify the taxonomy-$taxonomy-$term.php template to include posts from all sites in the network? I've been looking into the query_posts method from the Custom Queries Codex article, and ...
2
votes
2answers
214 views

Extending WP_Query — Optimise SQL query

I'm storing posts, a user follows in a custom table that has the columns id, post_id and user_id. To fetch posts that a user follows I have extended the WP_Query as follows: class ...
0
votes
1answer
33 views

Pagination not working with WP_Query (creates links but no page)

The following loop gets all posts within a relevant category. It does generate a pagination URL, but it does not take me there (it just redirects back to the homepage). Would anyone know why? $paged ...
0
votes
1answer
20 views

Custom conditions in wp query

This is basic query arguments . $loop = new WP_Query(array('post_type' => 'project', 'posts_per_page' => -1)); Now I want to pass custom arguments like 1.If it is front page post_type will ...
0
votes
1answer
63 views

Get the type of an advanced custom field (ACF) in a WP_Query loop [closed]

When reading posts with WP_Query how would I get the data type of an advanced custom field (textbox, date, number, repeater, …) ? My code: $loop = new WP_Query( $args ); $posts = ...
-1
votes
1answer
64 views

WP_Query with tax_query not working

I tried to create a custom query, but no results, it throws me an error. $args = array( 'post_type' => 'product', 'posts_per_page' => 1, ...