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
22 views

WP_Query retuning empty array in rest api

I recently started writing a rest api for my plugin. I need to access some custom posts however WP_Query is returning an empty array when I'm querying the db. There is the custom post type declaration....
user avatar
  • 1
0 votes
0 answers
13 views

Trying to change category of wp_query

I'm trying to change the category of the main loop, after printing posts from each category. The page shows: 3 most recent posts 3 posts from first category 3 posts from second category 3 posts from ...
user avatar
0 votes
1 answer
10 views

Reciving Error 404 blog/page/2/

I can't seem to understand the issue here with my pagination? when visiting /blog/page/2 page goes to 404 page. Help me guys? <div class="row"> <?php ...
user avatar
2 votes
1 answer
43 views

Using pre_get_posts on a specific core/query block

I’m trying to apply the pre_get_posts to a specific core/query block, in order to programatically modify the number of posts displayed when a custom attribute is set. If I use the render_block hook, ...
user avatar
0 votes
0 answers
9 views

Output product category link from WP_Query

I have a WP_Query that outputs products from given Product category name. For each product list I would also like to link to the category of that product, but I'm not sure how. My query: <?php $...
user avatar
0 votes
2 answers
44 views

How do I check if an article is popular this week?

I use this function to set and get post view of post in my WordPress function wpb_set_post_views($postID) { $count_key = 'wpb_post_views_count'; $count = get_post_meta($postID, $count_key, ...
user avatar
0 votes
0 answers
29 views

Any quicker alternative for WP_Query "NOT IN"

I am using the following wp_query to pull up a list of post, and I want to exclude a few categories of a custom taxonomy. It works well, however Query Monitor is telling me that the query is slow. I ...
user avatar
  • 123
0 votes
0 answers
18 views

Order WP_Query by meta_key priority when 'OR' relation used for multiple meta values

I have a WP_Query that queries posts by an ACF date field AND an ACF true/false field. I am requesting all posts that have a date field value past the current date OR have the true/false field ...
user avatar
  • 426
0 votes
0 answers
13 views

How to order query results based on if a custom field has been populated, then the order by the date of the post?

I am trying to custom sort a query for product posts (custom content type) based on if a specific ACF custom field for a product ID number has been populated. My client wants to feature products with ...
user avatar
  • 101
0 votes
0 answers
36 views

WP_Query order posts by category

In a custom WP_Query I want to order posts by category. I mean that I want to show posts with term_id=1291 first and then show other posts. when I use two WP_Query , I cant use pagination. "...
user avatar
0 votes
0 answers
12 views

WP Query Order By Multiple Values

I have created the following query. The query works perfectly. However, I despair with the order. I would like the posts in which the custom field "nft_featured" have the value "yes&...
user avatar
  • 1
0 votes
1 answer
82 views

Error: Attempt to read property "ID" on null

I have the following error Attempt to read property "ID" on null in this code snippet global $wp_query; $categories = get_the_terms($wp_query->post->ID, 'live_stream_categories'); $...
user avatar
  • 141
0 votes
0 answers
14 views

Display the same randomized query results on browser-back

I'm creating a query based on certain criteria and if the returning query yields more than a displayable amount of hits, I rand them. Which works great except if people navigate away from the query-...
user avatar
  • 21
0 votes
0 answers
31 views

WP_Query return posts in wrong order

I have a strange WP_Query behavior when using this query arguments: $qargs = array( 'post_type' => 'any', 'post_status' => array('publish', 'inherit'), 'post__in' => $...
user avatar
  • 1
0 votes
0 answers
23 views

WP_Query - How to query all of post types categories

I added a custom taxonomy to woocommerce's products post type. The custom taxonomy is called Brands and is simply used to select the brand of the product. I am using wp_query to query all of the ...
user avatar
0 votes
0 answers
23 views

get_terms with specific id order

I have the specific query $queried_object = get_queried_object(); $taxonomy = $queried_object->taxonomy; $term_id = $queried_object->term_id; $isActive = 0; $postTerms = get_terms( [ 'taxonomy' =...
user avatar
  • 3
0 votes
0 answers
48 views

Override WordPress core post-template.php block template

I need to modify the default markup generated using the render_block_core_post_template function located inside wp-includes > blocks > post-template.php. I don't see any other way of modifying ...
user avatar
0 votes
0 answers
17 views

How to work Woocommerce pagination inside shortcode?

I have a shortcode that shows the orders history placed by user. It works, however I have pagination with WP_Query which is not working. When I click on any page number the same page is reloaded, the ...
user avatar
  • 101
0 votes
1 answer
32 views

Why my query is not "Main_query"?

I made a new page in admin panel like this. I want my Query here to be main_query so the other plugins could hook it, modify limits, etc... add_action('admin_menu', function (){ add_submenu_page('...
user avatar
  • 1
0 votes
1 answer
33 views

Isn't Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}

I'm trying to count rows in sql table using SELECT COUNT(*) for the post view count. My code is function get_post_views($offset=0, $post_id){ global $wpdb; $get_visit_query = "...
user avatar
0 votes
0 answers
21 views

Filter sub-category from checkbox form

I’m having have a checkbox filtering issue in wordpress - Please have a look at the details below - Any help would greatly be appreciated! What I’ve built: I created three custom taxonomies of topics, ...
user avatar
0 votes
0 answers
10 views

Exclude post with taxonomy and from the terms (taxonomy & tag) posts count

Using the below code, i have excluded the taxonomy (slug:expired) from archive or tag or taxonomies pages in front-end. add_action('pre_get_posts','custom_get_posts'); function custom_get_posts($query)...
user avatar
  • 13
1 vote
0 answers
13 views

Multiple If Else with WP Query in Wordpress

Could anybody help me with this? I want to have max 3 post from this query: category name: activities But if the post is labeled with the tag private there must be a link with the words private link. ...
user avatar
1 vote
0 answers
9 views

Using hook to use DISTINCT in a wp_query

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) INNER JOIN wp_product dg ON dg.post_id = wp_posts.ID AND ( dg.location IN ('XV', ...
user avatar
  • 11
0 votes
1 answer
19 views

Wordpress search WP_Query to cover multiple post types and their custom fields?

I am trying to make the WP default search a bit more intelligent, by having it use custom fields. It searches through my custom post types, but only for the usual fields (excerpt, title, content). In ...
user avatar
0 votes
1 answer
17 views

Include current post into loop

I have a related posts loop ( in every single post page ) based on post title. source : https://wpza.net/get-related-posts-based-on-the-posts-content-in-wordpress/ But I also need to include current ...
user avatar
0 votes
1 answer
94 views

WP Query ordering on a meta field for posts with a date in the future not ordering by datetime

I have a WP Query: $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 5, 'category__in' => $postCategories, 'meta_query' => array( array( ...
user avatar
0 votes
0 answers
20 views

WP_Query for woocommerce products with a pattern as a post_title

I am trying to make a wp query for woocommerce products. This will be implemented for a search bar, so the consumer can search for a desired product. My first go was this: $args = array( 'post_type'...
user avatar
0 votes
0 answers
47 views

Tax Query on product_cat using NOT IN as operator does not exclude that category

Using the following code, I expect $items to not include products with the product category "stones." However, that is not the result. It doesn't seem to be excluding that category at all. ...
user avatar
0 votes
0 answers
23 views

Woocommerce Shortcode which displays a table with product data

I searched for the internet but didnt find anything which works to my use case. I want to have a shortcode which displays a table of products. In each row I want the product to have the following data:...
user avatar
  • 101
0 votes
0 answers
34 views

conditional filter

I'm trying to set up a filter that shows upcoming events (if any) or shows past events; function events_function($date_args){ $date_args = array( 'post_type' => 'evento', '...
user avatar
  • 1
0 votes
0 answers
32 views

Query ACF relationship field - Comparator IN - Value array

I have two custom post type with a relationship custom field to linked them. I try to do a query based on this custom field using the comparator IN and some IDs in an array, but so far with no success....
user avatar
  • 5
0 votes
0 answers
10 views

Page that lists publications by classifying them by taxonomy

I need a little help writing code. I have an "artists" CPT I have an archive-artists.php page with the code below, but I would need to add a "year" taxonomy. And that my artist ...
user avatar
0 votes
0 answers
14 views

Can I get one wp_query to double order like this?

I am trying to achieve the following: get a collection of posts that have meta_1 set to true at top of the list place posts that have meta_2 set to true, ordered by title end the list with the posts ...
user avatar
0 votes
0 answers
23 views

JOIN filter doesn't work in WP_Query in wp-ajax calls

In order to get list of objects I make new \WP_Query request to the database using posts_join filter (JOIN with other custom table). It works fine with direct loading of PHP page. But the same code ...
user avatar
  • 111
0 votes
1 answer
22 views

Meta Box WP_Query array for showing items with a certain relationship

in oxygen I am using a repeater to show posts that have a certain relationship. The advanced query in the relationship is post_type = "custom post type1" and then I add another parameter ...
user avatar
0 votes
0 answers
8 views

wp-query and wp_get_post_terms on custom taxonomy archive page

hi so I am just wondering how I can increment the pagination of a page based upon the terms found with wp_get_post_terms() rather than the post count for the page. this is the process i have: custom ...
user avatar
  • 16
0 votes
0 answers
10 views

Woo-commerce Update price as a Bulk from My offline software export

I have a WordPress + woo commerce online shop. In addition I have a local offline desktop software for my inventory products and pricing. I define a common code between my shop and my local desktop ...
user avatar
  • 1
0 votes
0 answers
12 views

Multi-layered WP_Query

I'm trying to avoid creating additional custom field for one of the posts, and was wondering if there is a way to query WP DB to retrieve the necessary data. I have 3 types of posts: Events, Programs ...
user avatar
  • 1
0 votes
0 answers
28 views

custom taxonomy pagination 404 error

I know this question has been asked a lot, and I have been searching for solutions and trying what I found but I am still having issues. When I click on page 2 I get the 404 error For example, I have ...
user avatar
0 votes
0 answers
30 views

Why is my pagination /page/2 taking me to index.php?

Why does my pagination take me to sites front page instead of page 2. The url seems to be correct mydomain.com/category/categroyname/page/2 but it doesnt display posts for 2 page. I tried to reset my ...
user avatar
  • 101
0 votes
1 answer
16 views

Ordering by meta value not working

I have set WP_Query to order by a meta value but it isn't ordering correctly for some reason. entry_key is a year but is stored as text eg: 2022 $term = get_queried_object(); $args = array( '...
user avatar
0 votes
1 answer
134 views

Merge 2 custom post type posts and taxonomy terms and sort ascending

We have a most recent block where we query a taxonomy for a custom post type and posts from two custom post types. This we do using this code Full Code <?php /** * Highlights block * **/ // ...
user avatar
  • 353
0 votes
0 answers
13 views

`offset` WP_Query argument dont work via `pre_get_posts`

I have some weird problem because pre_get_posts filter completely ignoring offset argument. Here is function from functions.php file: function custom_category_query (WP_Query $the_query) { if ( !...
user avatar
  • 145
0 votes
1 answer
24 views

Use get_cat_ID to retreive multiple category IDs

I am trying to use the names of categories stored in user meta (ie users' preferences) to control an on-page query’s parameters. $topicsofinterest = get_user_meta(get_current_user_id(),'...
user avatar
0 votes
0 answers
32 views

Function the_posts_pagination() not compatible with WP_Query arguments

I trying to make a list with posts from specific category. It's supposed to work as the loop in category.php file. Unfortunately i have problem with pagination links which are completely not ...
user avatar
  • 145
1 vote
0 answers
33 views

Overwrite YoastSEO meta-tags with another page's [closed]

I'm writing a custom Wordpress theme and for a specific page I need to overwrite its meta-tags (printed by YoastSEO) with the meta-tags of another page I already know the ID of. I cannot just change ...
user avatar
  • 11
0 votes
1 answer
21 views

Filter products on category AND tag

I want to be able to filter products based on category AND tag, as well as sub category AND tag. From my research I heard that I must write some kind of rewrite rule in functions.php for this to be ...
user avatar
0 votes
0 answers
13 views

Custom wp-query display post only today

I have a problem. My query not display the post only today. $today = getdate(); $query = new WP_Query( array( 'post_type' => 'tips', 'posts_per_page' => '9', 'order' ...
user avatar
1 vote
1 answer
10 views

Fastest way of counting posts of a custom post type in a specific taxonomy term?

I know this kind of question is legion but I have read through all related topics and I can't find a satisfying solution. What I want to achieve is simple: on my taxonomy (author) term archive page I ...
user avatar

1
2 3 4 5
111