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
0 answers
36 views

How to short circuit a wordpress query that is not related to posts?

How to short circuit the below query via hooks such that the query is not run based on a condition? I tried using pre_get_posts filter but that is for posts queries only. The query runs as a part of ...
dc09's user avatar
  • 195
0 votes
0 answers
41 views

How to speed up WP_Posts_List_Table __construct() Query on a wordpress website with over 1 million posts?

On a website with over 1 million posts, the following from class WP_Posts_List_Table __construct() is taking a long time: SELECT COUNT( 1 ) FROM wp_posts WHERE post_type = 'shop_order' AND post_status ...
dc09's user avatar
  • 195
0 votes
2 answers
31 views

How WP determines archive page vs single page?

I have a confusion about how WP loop works on archive pages vs single post or page? when you request an archive url, it shows all the related posts with only title, excerpt etc. but when you request a ...
yucelm's user avatar
  • 1
0 votes
1 answer
15 views

WP Query filtering by custom category not showing all relevant posts

Here's a question I've been trying to solve all day: I added a WP Query that would show posts from a category that the admin chooses with a custom field. The post is a custom post type called "...
Jillian Hoenig's user avatar
0 votes
0 answers
21 views

Products are displayed only in the admin area

I have a code: $products_query_params = array( 'post_type' => 'product', 'product_cat' => 18, ); return new WP_Query($products_query_params); I need it to get products. But it works ...
Wembley's user avatar
0 votes
2 answers
33 views

Why is my nested 'OR' meta_query not working?

I have the following code which I think should work but obviously i'm missing something. Anyone who can tell why this is not correct? //EDIT Here is what needs to happen. 'Merk', 'Type' and 'Dummy' ...
Mart van der Kruis's user avatar
0 votes
0 answers
27 views

Applying a custom query for the AJAX "us_ajax_grid" function (from WPBakery)

I have some custom queries that are working properly with pagination if I use the regular pagination numbers, but I want to use the pagination as "page load on scroll" and then apply my ...
Pedro's user avatar
  • 33
0 votes
2 answers
47 views

Removing filename searches when searching attachments

My website's db is quite big. I have some 350,000 images in the media library (as well as some 350,000 posts). My wp_postmeta table has 4,580,552 rows. As a result, some queries are insanely slow and ...
Biranit Goren's user avatar
0 votes
1 answer
17 views

Check for a value in a custom query

I have a custom query to show people working in a specific division (label) in an organisation. I want to display the specific division’s name before the cards of the people are displayed. Currently I ...
Woohoo's user avatar
  • 1
0 votes
2 answers
16 views

Multiple meta value orderby clauses in a WP_Query

Is there a way to allow for multiple meta value orderby clauses in a WP Query? I have a query which retrieves records between meta keys start/end, and orders them ascending. I’m adding a new key for ...
commadelimited's user avatar
0 votes
0 answers
10 views

What is the best way to offset previous posts on the same page?

I have some main pages with multiple custom query like : all posts with filter X, all posts with filter Y, etc... I would like to make a last query for ALL posts, but exclude or offset all the posts ...
Gregory's user avatar
  • 584
2 votes
1 answer
72 views

Understanding the 'AND' Operator in WordPress WP_Query's tax_query

WP_Query is a very rich object but sometimes confusing. I want to know if these syntaxes mean exactly the same thing: bringing posts that belong on the same time to both categories 76 and 78 (...
AFA Med's user avatar
  • 183
1 vote
0 answers
7 views

Same query args showing different results order when setting different number of posts

This query using the same arguments is returning different posts order: sample / test codes: // Query 1 $query_args = [ 'post_type' => 'business', 'showposts' => 8, 'no_found_rows' =&...
FatMiming's user avatar
0 votes
1 answer
19 views

Implement AJAX 'load more' with offset posts

I am trying to implement 'Load More' functionality via a button in a WordPress theme. We are starting by displaying the first five posts using pre_get_posts in the standard WordPress query and, when ...
Alex Ryans's user avatar
0 votes
1 answer
32 views

Loop a Single Taxonomy and Output all Posts Associated (but also show a message for empty ones)

I have a custom post type for Vacancies, with a Taxonomy of Location set up. What I've achieved is looping through all Locations and then showing underneath associated posts. Update: Thanks to @...
AP_19's user avatar
  • 3
0 votes
0 answers
22 views

Custom Wordpress Archive and query dont filter by categories

I have a problem. I am using Hello Elementor child theme where I made new archive template. Now I added a category to the menu through categories menu item. The problem is that posts are not filtering ...
ERM-AL's user avatar
  • 1
0 votes
0 answers
10 views

Query for posts belonging to multiple categories

Within the default Post categories I have A parent category Cities -- City A -- City B -- City C A parent category Beauty -- Hairdressers -- Pedicure A parent category Sightseeing -- Archeological -...
Brecht Schoeters's user avatar
0 votes
1 answer
27 views

wp_logout action hook is not firing

Why the user meta value is not being changed after logout using the following code: function update_login_status_on_logout() { $user_id = get_current_user_id(); if ($user_id) { ...
rock's user avatar
  • 1
0 votes
1 answer
19 views

Query top level custom post in taxonomy

This is my first post, I'm a bit stuck. I have a custom post (dan) and taxonomy (dnas), with hierarchical categories. I want to make a query resulting in posts at toplevel (hoofdcategorie01, ...
Dennis's user avatar
  • 1
0 votes
0 answers
34 views

WP_Query: how to sort all posts by date when one category has a custom "date" field?

We have a couple of hundred posts that are spread across 4 or 5 categories and so far we've been just fine with sorting by publish date. We recently added an "Event" category that has a ...
cmlb's user avatar
  • 1
0 votes
1 answer
27 views

Group users by meta field, with name of meta field as group title

I'm creating a employee photo directory based off users from my site. I'm trying to add front end filtering for this query and I have it mostly working. What I'm trying to accomplish is to sort the ...
NW Tech's user avatar
  • 717
0 votes
2 answers
26 views

post loop with different design depending on post

I'm having a lot of trouble finding the solution. I would like to loop my last 3 posts with wp-query. I would like the 1st post to be in one div and the last 2 posts in another different div. So when ...
Thica's user avatar
  • 15
0 votes
0 answers
18 views

How can I make the hero image full width, while keeping the contents below it contained, without the scroll bar appearing when viewing it?

I'm trying to make the hero image full-width so I chose full-width on the block alignment tab. I'm trying to keep the contents below it contained, so I chose "contained" for the page setting....
Raven's user avatar
  • 1
0 votes
0 answers
19 views

Optimizing AJAX Query with Large Database

I have a WordPress AJAX function that performs a location-based search on a website with a large database of over 100,000 posts... The function is responsible for querying the database to find the ...
Francisco's user avatar
0 votes
1 answer
48 views

Complicated `orderby` based on text in custom field

I'm doing a user query and looking to query users that are in a certain department (custom field) -- this works. Now I'm trying to manipulate the order....I'd like to use the meta_key for position and ...
NW Tech's user avatar
  • 717
0 votes
1 answer
44 views

Wordpress custom post type -> query and sort by custom field with multiple values, then published date

I have a custom post type with 2 custom fields that I am trying to sort by: The first custom field is "featured post" (yes or no values). The second custom field is "CPT images ...
Mitch S's user avatar
  • 27
0 votes
1 answer
29 views

wp query order posts by custom taxonomy doesn't work correctly

I have custom wp query and i need to sort it according to taxonomy called 'consultation_records' which contains years 2017, 2018, 2019 etc. I used this code but the result is the posts not ordered ...
Yehia Gamal's user avatar
0 votes
0 answers
12 views

How to display posts from home page in blogs in category wise

actually i am converting html to wordpress and i have posts on home i want to display them on blog page in category wise rightnow my blog page in working on index.php, I have made some post dynamic ...
Mujtaba's user avatar
0 votes
0 answers
18 views

Create an archive page by combining two post type

I wanna create an archive page for both normal posts and a custom post type(gallery). I created an index.php file and put my code in there but its pagination ain't work correctly. all pages look the ...
Poorya Ghorbani's user avatar
0 votes
0 answers
16 views

WP_QUERY with both author and post_type set (makes me crazy)

If I do this $args2 = array( 'post_type' => 'post', ); $query2 = new WP_Query($args2); error_log($query2->request); Then I see this result SELECT ...
Ioria's user avatar
  • 11
0 votes
0 answers
13 views

How to make posts_like_dislike reference current post when iterating?

I am using plugin https://wordpress.org/plugins/posts-like-dislike/ . It adds a [posts_like_dislike] shortcode. When inside the default wordpress Twenty Twenty-Three in posts "Blog Home" ...
KamilCuk's user avatar
  • 101
0 votes
0 answers
13 views

Include custom post type that matches taxonomy field in another custom post type

I have two custom post types, one is “maker” and the other “product”. (used ACF plugin) I have a taxonomy field for Business Name, this field is called “choose_business” in the product custom post ...
Nik Nak Sim's user avatar
0 votes
0 answers
12 views

AND and OR in my CPT search query depending on checkbox

I have a checkbox, that when checked is supposed to change a query from AND to OR. The moods, genres and the checkbox data comes through just fine via a ajax call, and based on this, it will filter a ...
Jannickla's user avatar
0 votes
1 answer
22 views

Wordpress duplicating posts from single loop

I've created a custom post type with ACF custom fields included. The CPT is being placed inside of a bootstrap slider. Everything seems to be working, except, the posts being rendered on the page are ...
Mitch S's user avatar
  • 27
0 votes
0 answers
18 views

author archives, showing all custom post types, problem on pagination

Please, look at the link to the page I need support with. This is a website where several “authors” make their reviews on books or create some original posts. This page shows “Badges” which are all ...
Ioria's user avatar
  • 11
0 votes
0 answers
12 views

How to assign a single-menu-template to a menu-items in a taxony/ cat/ subcat/ subcat-item

Hi hope really someone can assist. I have created a single-meny-template with post-type-meny, and I have created taxonomy, categories, sub-categories and subcat-items. What happens is that the ...
Brango's user avatar
  • 1
0 votes
0 answers
32 views

Use Custom Field to Display Post Loop

In my custom template I have created a menu which is a row of 10 horizontal tabs. Each tab shows a date which is defined using an ACF datepicker field in the post. I have also created a custom post ...
SavPhill's user avatar
  • 118
3 votes
1 answer
70 views

Force new posts to the top of query loop

I have a query where the posts is ordered by title. I am trying to filter into the (main) query in order to have the newest (created in the last 14 days) on top of the loop. Below the newly created ...
pstidsen's user avatar
0 votes
1 answer
17 views

Sort wp_query of two post types using meta datefield for one and date for the other - possible?

I have two queries that result in id-arrays that I merge into a common array which, in turn, has all the posts I need from the two post types (posts, events). However, in the sorted list I would like ...
yms's user avatar
  • 35
0 votes
1 answer
25 views

Custom fields disappearing when a custom post type is assigned

I have a custom taxonomy page. This custom taxonomy has a few custom fields to populate it's template. A user is able to assign custom post types and media to this custom taxonomy and then those posts ...
solariati's user avatar
0 votes
0 answers
20 views

WP Query - Posts repeated on different pages when using pagination and orderby => menu_order

$q = new WP_Query([ 'post_type' => 'post_type', 'posts_per_page' => 10, 'orderby' => array('menu_order' => 'ASC'), 'paged' => ((...
Dan.'s user avatar
  • 836
0 votes
0 answers
37 views

How do I change a variable in a Wordpress query with a select menu dropdown option and reload the WP query

I'm implementing a drop down menu that is populated with brand names of products. It's populated dynamically with the title(s) from a wordpress custom post type (axiss-brand). When the user selects ...
KKA's user avatar
  • 1
0 votes
1 answer
25 views

Conditionaly move certain posts at the bottom of the query result

How can I move certain posts returned by WP_Query to the bottom of the results? I am using this method.. $exp_args = array( 'post_type' => 'apartment', 'posts_per_page' => -1, '...
Abhik's user avatar
  • 2,886
0 votes
0 answers
109 views

Sort posts by category and date using php and custom query

I am using Elementor Pro and Advanced Queries and also ACF for custom date. I have 2 types of posts that are events - event 1 and event 2. I have an event calendar on the first page showcasing the ...
Tryandcry's user avatar
0 votes
0 answers
23 views

How to Show Standard Post and Custom Post in Same Section at Homepage?

I'm trying to show both my standard posts and custom posts on my homepage. I've got the following code working, but it's causing a 404 error if I assign a custom homepage. If I keep the setting of &...
Ayushvam's user avatar
0 votes
1 answer
50 views

Is it possible to use the_post 2 times in one loop

I have a page on which I want to display all my posts from my custom post type, which I am able to do in a single column. However, I want to display the posts in 2 columns. For this, I will need two ...
Romit's user avatar
  • 1
0 votes
0 answers
283 views

Gutenberg block: add a multi-select for posts

I created a custom Gutenberg block with @wordpress/create-block. I now have a dropdown where you can select a post, but I would like this to be a multi-select where you can select multiple posts. How ...
azrac's user avatar
  • 1
0 votes
0 answers
34 views

Add css class ID to largest and smallest number a custom field in wp_query

I have a wp_query for get a ACF number field. I want to add a css class ID to the largest and smallest number in the loop. <ul> <?php $editor = new WP_Query( array( '...
och's user avatar
  • 29
0 votes
1 answer
26 views

How to show correct td of table tags in wp_query loop

I Have this loop: <?php $post_ids_fetched = array(347, 258); $editor = new WP_Query( array( 'posts_per_page'=>4, 'post_type'=> 'earth', 'post__in' =&...
och's user avatar
  • 29
1 vote
1 answer
26 views

Wordpress DB query

I want to capture some data from a WP website I'm building. The website will show a game to play for each calendar month (12 games). Players can come and play at any month of their choosing. If they ...
Sam's user avatar
  • 11

1
2 3 4 5
115