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

hide each link of post id onclick with localStorage

I display a list of post id on a page and I want each clicked post id link to disapear. I use the following code but the disapeared link comes back after the page reloads. In this case, how to use ...
user avatar
0 votes
0 answers
11 views

Free search and custom taxonomy query not providing the same result

Two queries that should function the same, provide different results. I've created a custom post type called maarchey_shiur. I've created a custom taxonomy called maarchey_shiur_categories. If someone ...
user avatar
  • 96
0 votes
2 answers
23 views

Custom post type loop with custom category filtering

Can anyone help me here. I want to list all the custom posts with the type 'portfolio' in this loop, where they have the 'Project Categories' set to 'ABC'. The below doesn't work, I think the issue is ...
user avatar
  • 101
1 vote
1 answer
10 views

Why isn't my `meta_query` array functioning properly?

I am trying to include a meta_query to only show the 'post_type' => 'want-to-sell-post' that have the key 'key' => '_wpcf_belongs_artist_id',. Right now, all want-to-sell-posts are being ...
user avatar
0 votes
1 answer
14 views

Conditional operator OR not working with custom fields

OR operator is not working for both conditions, only check first value if true then code executed and if first is false then not check 2nd condition and return else output. I also try with LIKE ...
user avatar
0 votes
0 answers
26 views

How can I return only IDs from the `posts` REST endpoint?

I have the following code: const FORMS = document.querySelectorAll(".search-form"); FORMS.forEach((form) => { const INPUT = form.querySelector(".search-form__input"); ...
user avatar
  • 1,101
0 votes
0 answers
11 views

Post incorrectly excluded when using "category__in"?

I have a wp_query using the following arguments. While I have the 'category__in' line commented out, I get all 3 results I should. Shown below with the IDs of the categories they belong to. Category ...
user avatar
0 votes
0 answers
31 views

get_children() Archive Template

This is my first attempt at coding & I have come unstuck with the wp_query loop integration. I just want to build a template for a page that will check for children and list their respective ...
user avatar
  • 1
1 vote
0 answers
17 views

Wordpress Loop and $post

I decided to take a closer look at how WP works and ran into this question. I see that when WP is loaded, the wp() function is triggered, which will parse the request and get data from the database in ...
user avatar
  • 11
0 votes
0 answers
8 views

How to WP_Query posts order by parent title?

How do I return a posts from WP_Query ordered by their parent's title? I know how to do it in the way where I return ALL posts and then change the order afterwards with array sorting. But I wanna know ...
user avatar
0 votes
0 answers
20 views

Optimal WP Web App Backend for mobile app development

I'm having a web app built on wordpress, and am needing to build a mobile app with it. The probably most important aspect of this is that I'll need to transform all of my AJAX request-responses to the ...
user avatar
  • 286
0 votes
1 answer
16 views

Reset postdata not working on WP_Query in functions.php

I'm running a WP_Query in my functions.php, so I can easily access some ACF-fields in my code without having to run that query on every page. However, the loop changes the post ID to the CPT I'm ...
user avatar
  • 279
0 votes
2 answers
28 views

How to get all user posts from two post types in wp_query

When I add 'author' I only get results from "post" but no results are received from the "my_post_type_name" My code: $args = array( 'author' => $user_id, '...
user avatar
0 votes
1 answer
60 views

complex get_posts() query to select child pages

I have pages on 2 levels under the main deparments page like below. Departments --Department 1 -----Course 1 -----Course 2 --Department 1 -----Course 3 -----Course 4 --Department 3 --Department ...
user avatar
  • 31
0 votes
1 answer
6 views

How do I reset $wp_query in a function?

I'm using a function in my functions.php that finds a specific post in a custom post type depending on a slug. I was wondering if I need to reset $wp_query because I use $wp_query = $posts and $...
user avatar
  • 1
0 votes
0 answers
22 views

Show Posts via cat1+cat2 in URL that are in both Categories doesn’t work

it seems like i am the only person on this planet currently experiencing this issue. When i search for www.gooloo.de/category/balea+vegan, it should only show posts, that are in BOTH categories, but ...
user avatar
0 votes
0 answers
27 views

WP_Query get posts in custom database table [duplicate]

I have a custom database table like this: How can I get the 5 posts of custom post type whose ID appears most times? Thank you!
user avatar
1 vote
0 answers
11 views

How can I create 'future' and 'past' parameter for restAPI by filtering the CPT custom date field by greater than / less than current datetime?

add_filter( 'rest_events_query', 'filter_events_by_date_field', 999, 2 ); function filter_events_by_date_field( $args, $request ) { if ( ! isset( $request['filter_date'] ) ) { return $args; } $...
user avatar
  • 11
0 votes
1 answer
22 views

Display if author page is author page of current user

in my multi author website I have a button that users can upload their avatars. I need to display this button in author page. I can do it. I added this button to author page. The problem is that ...
user avatar
0 votes
0 answers
20 views

Query multiple post types, but different order for each

I have a query which searches 2 post types as below: $args = array( 'post_type' => ['post', 'promotion'], 'posts_per_page' => 12, 'paged' => $...
user avatar
0 votes
0 answers
23 views

search.php to search only the post title

I'm trying to rewrite my search.php to search only for the post titles because I have a ton of posts published to my site (around 400k), which slows down the search speed to about 20s per search. <?...
user avatar
0 votes
0 answers
20 views

How to search by slug and old slug in single API

I need to search for wordpress posts with input slug or old slug only 1 parameter in single API. Now I'm using 2 url: 1. /wp-json/wp/v2/posts?slug=hello-world 2. /wp-json/wp/v2/posts?meta_key=...
user avatar
0 votes
1 answer
42 views

How to set up hierarchical relationships without using plugins / meta query

I'm running a large database of musical artists and their releases. I inherited the site after it running for a long time. There are currently several different custom post types, created with a ...
user avatar
0 votes
1 answer
27 views

Count posts per taxonomy else change taxonomy if less than x number

$taxonomy = $tag->count > 3 ? 'post_tag' : 'category'; $cats_or_tags = $tag->count > 3 ? $tag_ids : $cat_ids; $args = array( 'tax_query' => array( array( 'taxonomy' =&...
user avatar
  • 446
0 votes
1 answer
37 views

How to add custom meta to 'pre_get_terms'?

I have a custom taxonomy with custom meta. I have added the custom meta values to columns in the admin list page just fine. But if I search for values that are in these columns nothing is found. I'm ...
user avatar
  • 281
0 votes
1 answer
31 views

How to add $args to any running wp_query from function.php?

Is it possible to add WP_Query arguments from functions.php to any of wp_query running on current page? For example, I want to add $args['order'] to current running wp_query on any pages.
user avatar
0 votes
0 answers
24 views

Related posts by current posts child category

I'm trying to use this code to display related posts by the same category as the current post but if the post is in a child category, i need to show related posts by that child category, not the ...
user avatar
  • 446
0 votes
0 answers
35 views

WP query taxonomy optimization

Is there any way to speed this query? Noob here. SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND (...
user avatar
0 votes
1 answer
30 views

Let current user know pending posts counts using wp_query

I'm working on a query to let a logged-in user know if the user has more than 5 pending posts. Here's what I ended up with: // Start the query $query = new WP_Query( array( 'post_type' => '...
user avatar
  • 175
0 votes
0 answers
20 views

How to add date_query to meta_query array

I am building a meta query array and all fields for the user are optional so some might not have any data. But there is also an option which requires a date query. I am still checking to see if this ...
user avatar
0 votes
1 answer
29 views

date_query empty results with custom post type

I am trying to use get_posts to return data between certain dates but I always get an empty result even though there is a lot of data. This is for a custom post type. $args = array( 'post_type'...
user avatar
0 votes
2 answers
30 views

Order by the first array within a meta_query

I would like to sort the output of my WP Query. I want the events that are coming up soon to be at the beginning. The events that have already taken place should be at the end. So the first array in ...
user avatar
0 votes
0 answers
35 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
19 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
13 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
2 answers
68 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
10 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
48 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
30 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
27 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
15 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
42 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
442 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
34 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
24 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
24 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
56 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
26 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

1
2 3 4 5
112