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

WP Query: If field X is empty, show posts based on field Y

Sorry for the bad title, had difficulties phrasing this questioon in a TLDR fashion. I have a custom post type for events on my website. Some events only happen in one day, whilst other events might ...
0
votes
0answers
30 views

Query custom post type that has a serialized relational advanced custom field value

I have a custom post type "issues". I am using Advanced Custom Fields to add a relational field called "articles_from_this_issue" where the admin can select multiple articles. I ...
1
vote
1answer
16 views

Wordpress search posts by author name with autocomplete

I am using autocomplete code as follows: functions.php // add the ajax fetch js add_action( 'wp_footer', 'ajax_fetch' ); function ajax_fetch() { ?> <script type="text/javascript"> ...
0
votes
1answer
37 views

Using a new WP_Query inside the loop

I'm trying to query the database to count log entries for file downloads, this is then displayed an the thumbnail when listing search results. From Search.php ` <?php //JAYJAY Get the download ...
0
votes
1answer
27 views

Why are my wp_query args being ignored if post_type = CPT

I have a few different CPTs setup; 'jobs', 'events', 'products'. They are being displayed on various pages of the site, in sidebar or footer areas. Using the following code, my CPT gets output, but ...
0
votes
1answer
16 views

Error in pdf generating plugin using FPDF

I'm trying to create a plugin using FPDF to create an options page to print custom post types. Here is my code: <?php /* * Plugin Name: RT FPDF Tutorial * Description: A plugin created to ...
0
votes
1answer
40 views

Exclude a specific post in a Custom Post Type

I have a very simple query to display all my posts in a custom post type: <?php $page = get_page_by_title('Duck'); $args = array( 'post_type' => 'sessions', 'post__not_in'...
0
votes
1answer
30 views

Adding a tax_query to a WP_Query Object

Is it possible to modify a WP_Query object to add a tax_query? That is -- I'm able to add a tax_query when instantiating a WP_Query object $q = new WP_Query(array( 'post_type' => 'post', '...
0
votes
0answers
19 views

Wordpress rewrite with custom parameter doesn't work

I'm currently developing a plugin which takes a parameter from URL (example: example.com/product_id/1234 is converted to example.com) and passes it in WP_Query (supposedly this should be used instead ...
0
votes
0answers
16 views

Manipulated offset and pagination, can't display last post anymore

As you can see from the code below, i'd like to show the last post with a design and the other posts with a different design on the first page. For the rest of the archive pages the last post won't be ...
0
votes
1answer
11 views

Query pages created by deleted users

I need to query all and any pages that are created by either deleted users or users that are no longer users of the website. Here is my query $args = array( 'author' => '0', 'post_type' => '...
0
votes
0answers
9 views

have to do a while have post to show for two custom post types sharing the same taxonomy?

So I have 2 custom post types. One is a Location that has a hierarchical taxonomy called state. So basically one location page being Salt Lake City which belongs to the Utah state Taxonomy. The other ...
0
votes
0answers
24 views

Using Ajax and WP_Query to load more posts on category page fails

I'm using the code below to load more articles on click beneath the 10 posts that are already loaded on page load. It works perfectly on my front page, but when I use it on my category page, it will ...
0
votes
0answers
19 views

Add metabox if there is at least one post available

So I am building a WordPress Dashboard widget which will showcase all posts & pages where a Gutenberg Block is active. The below code does it's job and pulls in an array based on get_posts(). Here ...
0
votes
1answer
26 views

How to use custom page for all posts with custom url, call another directory?

I have tried many different codes: <a href="<?php echo get_template_part( 'template/test/post' ); ?>"> Test 1</a> <a href="<?php echo ...
0
votes
0answers
11 views

Dynamically load Woo Products in Block for landing page via Querry String Param

First time posting here. I am trying to load woo commerce products based up a query string param for a content block on a landing page. I only need this for two variables "Product Category" ...
0
votes
1answer
19 views

What database state changes happen after a post is manually "updated" with no changes?

After importing a series of posts (using WP All Import), my (custom) page template is unable to access the post's contents/fields. However, if I open the post in the editor and click "Update"...
0
votes
1answer
23 views

Display Parent-Child Posts in specific order by comparing IDs in array

I have an array of IDs stored for custom post type "service". Some of these are parent IDs and some of these are child IDs. So "service" post type here is hierarchical. Now from ...
1
vote
1answer
27 views

WP_Query: "post_parent" and "post_type" combination returning strange results

I'm experiencing some interesting results using post_parent along with post_type (local, WP 5.8): I have a custom post type project (with 'hierarchical' => true) where I'm grabbing all child posts ...
0
votes
0answers
14 views

How to hide specific page on any part of dashboard for everyone?

I want to hide specific pages for everyone in any part of WP dashboard, user role is not important. Help. I have tried something like this: add_filter('parse_query', 'hide_pages_in_wp_admin'); ...
0
votes
0answers
15 views

WP_Query paged is not work

I'm sorry, I speak a little English. 10 posts per page: $posts_per_page = get_option( 'posts_per_page', 10 ); There are a total of 10 posts. I see this 10 posts: $the_query = new WP_Query( array( '...
1
vote
0answers
34 views

Query posts(CPT, pages , hierarchical) by Ancestor ID

so i have a custom post type with hierarchical structure. Looks like this: top level 1 - child -- grand child -- grand child - child -- grand child top level 2 - child ...
1
vote
1answer
16 views

Custom post ui plugin & WP_Query - Polylang

I used to have a multilingual website translated with Qtranslate but now I am changing this to Polylang. I had a wp_query (below) that was working fine and when converted to polylang shows that no ...
0
votes
0answers
38 views

wp_Query with mutuplea values returns all posts

I have a dynamic form that brings the data from the URL and searches the DB with a wp_Query. It works great if I insert a dingle value manually. but if I pass the data from the URL I receive all the ...
0
votes
1answer
29 views

queried_object using pre_get_posts gets notices and warning

My code is getting me the result I want on my page, I'm fetching another post and my theme is outputting all of the relevant data I need on the page as expected. function replaceQuery( $query ) { ...
0
votes
0answers
44 views

How can I order a post query's results based on the number of matching taxonomy terms?

Say I have a number of posts, across several post types. Each of these posts are members of several taxonomies. My queries will be AND across taxonomies, but OR within a taxonomy. I would then like to ...
0
votes
1answer
18 views

Use dedicated functions

In the following page template, an additional JS script (“carousel.js”) and additional CSS file (“carousel.css”) should be loaded. How to run these files using WordPress dedicated functions? <?php /...
1
vote
1answer
39 views

API response to be stored locally

Is it possible to refactor the code so that the API response would be stored locally for one day, instead of retrieving the data from the API each time the page loads? <?php // Assume "$...
0
votes
1answer
22 views

wp query to use both author id and meta_query

I'm trying to display posts of an author by id OR those posts which have a meta value as author ID. I have a custom field in the posts section as Additional Author (additional_author) and now I want ...
0
votes
0answers
21 views

wp_query with pagination via ajax in WordPress

I want to show custom posts by WP_Query with Pagination in WordPress. When I click the next button, then reload the page & go to admin-ajax.php. But Posts are load well, the main problem is ...
0
votes
2answers
24 views

Random item on Custom Query working Local but not on live

I have a project that contains a button supposed to generate get a link to a random Custom Post item. I made my Custom Query as follow: <div class="content"> <?php ...
0
votes
0answers
10 views

Advanced Wordpress Search with multi values of a single term

I have a custom field named Sizes , small, medium, large, extra large, so a given post may have multiple option selected for Size parameter, a user can select multiple options for a post from this ...
0
votes
0answers
29 views

Unable to get pagination working using combined WP_Query

So I've been battling this for like a week now and it's impossible to find a solution, so I am reaching out to see if anyone could assist me. I want to paginate through my total 13 posts and just ...
0
votes
0answers
19 views

Query post by ACF User field

Hello I created a post type with ACF User field (multiple select). The idea is only the selected users will be able to see the post. Current users will only see the posts assigned to them. But my ...
2
votes
1answer
46 views

Ordering Custom Post Types with WP_Query

I want to output my custom post types in the order I have them in my post_type array. Or menu_position from register_post_type or literally anything I can control (aside from flex order). Any advice? $...
1
vote
1answer
23 views

Query with a meta value inside a given range

Quick question: I would like to retrieve some pages/posts with a meta value inside a range, eg) $min<$meta_value<$max for ordinary $meta_value there was a way to get pages/posts like this: $args ...
0
votes
0answers
27 views

Load more posts using AJAX based on posts inside WP_Query

So this is something that I have been battling with for some time now and I can't figure out how to "Load More" posts using AJAX with a combined query. Is it possible to AJAX Load more with ...
0
votes
0answers
14 views

WP_query not loading posts with pagination if posts_per_page number is larger than posts that are published

For some reason WP_query will return no posts if I set the posts_per_page to a number larger than the number of posts that are currently published of that custom post type. One would assume that ...
0
votes
1answer
39 views

Show posts from two specific category in WP_Query

I've two category employee and full-time. If a post publish in both (employee and full-time) category then the post will show in his specific section. If post has only employee category, not full-time ...
0
votes
1answer
25 views

WP_Query object: what's the difference between [query] and [query_vars]?

I'm debugging a query created by the Post widget of Elementor, it should exclude the post with id 12419. I see the [post__not_in] => Array ( [0] => ...
1
vote
0answers
20 views

How can I display a custom field from all posts and order them individually from their parent post

I have a post_type of 'interview' and within it is a repeater field 'interview' and sub_fields 'question' and 'answer'. I would like to display all questions and answers from all interviews and ...
0
votes
0answers
24 views

Combine relationship posts with existing wp_query

So I am building a query, and I wanted to see if someone can assist me on a special attempt to infuse two queries. So here is what I'm attempting to do: Check if we have any relationship posts, which ...
0
votes
0answers
13 views

Generate custom output on URL with directory

I'm trying to create a custom URL where I will output some string. The problem is that I want this URL to include a /.well-known/ directory and when I do this, 403 forbidden error occures. So my ...
1
vote
1answer
92 views

What's wrong with this WP query?

With kind help of Sally CJ who answered my question, I was able to create a Wp Query, but it still gives me unexpected results. When I write the quaery in raw MySQL, it works fine, but with the query ...
0
votes
0answers
22 views

wp_query order by sum of multiple values

I have review as a custom post type, and in this review there are fields that is representing part of the rating. I have been trying to find a way to sum fields up in to one number and then order by ...
0
votes
0answers
41 views

prevent get_comments() from returning comments not in comment__in

The query string comment__in takes an array of comment IDs to include. I have an array of comment IDs that I would like to assign to comment__in, such as $args['comment__in'] = $comment_IDs;. Some ...
0
votes
1answer
12 views

Having Issue on Ordering CPT by Custom Field In Custom WP Query

Having a Custom Post Type loop like this, I am able to return the result on page BUT I am not able to set Order By of display using my own Custom Field. As you can see here $topic_number = ...
0
votes
1answer
21 views

How to query for all posts that have a particular meta key?

I have many posts. Some have meta data, with a key called "foo". How can I query for just the posts with the meta data "foo"? metadata_exists requires the post ID, I'm trying to ...
2
votes
1answer
33 views

How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?

Example: $query->set('s', 'foo bar'); - search foo bar I want set search as foo bar OR lorem ipsum dolor OR ping pong
1
vote
0answers
23 views

Custom query filter by multiple ids in elementor

I’m following the Elementor official tutorial to create a custom query filter to display a list of posts retrieved from a custom field in a page (let's call them 'featured posts'). The code is the ...

1
2 3 4 5
109