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

Can't fetch Custom Post Type Data through Custom Query

I have a custom taxonomy "Shade Type" which contains two types Ready Mix DCM I am querying the DCM value to display in WooCommerce tab. My code is fine but I am not getting any values in ...
Hasnain Ghias's user avatar
0 votes
1 answer
30 views

how to get Nearby zipcode

I need to get close/Nearby to zipcode list data zipcode so I'm using the example table name li_zipcode: id zip_code latitude longitude 1 35004 33.557327 -86.534508 2 35005 33.604744 -87.042442 3 ...
Shiv Singh's user avatar
0 votes
0 answers
70 views

Combine query in WP_User_Query()

I am new user of WP_User_Query(). I don't know how to express whole situation. If I use below code I am getting good result. $users = new WP_User_Query(array( 'meta_query' => array( ...
Foysal's user avatar
  • 449
0 votes
1 answer
45 views

Loop increase in while loop not working

I'm aiming to create a layout where the first post is full-width in the loop, all the posts after are 50%. I created this code: <?php if ( $query->have_posts() ) : ?> ...
Pbalazs89's user avatar
  • 115
-1 votes
1 answer
435 views

Wordpress pagination returns the same posts

I did search the other posts here related to this problem, and tried all of them in my case, but I can't seem to make it work (probably because I don't know enough code) Can you please help me with ...
vyperlook's user avatar
  • 177
0 votes
1 answer
126 views

Wordpress Query - Display 5 posts (same post type), each from a given tag

We have a news section on our website. We have basically 5 companies giving publications: ('ENEFI', 'dmker', 'megakran', 'otp', 'futuraqua') We would like to list the latest one from each and order ...
Pbalazs89's user avatar
  • 115
1 vote
2 answers
167 views

Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX

I'm querying posts using the following wp query: function custom_retrieve_posts_function() { $paged = get_query_var( "paged" ) ? get_query_var( "paged" ) : 1; $args = array( ...
DevelJoe's user avatar
  • 487
1 vote
0 answers
344 views

Sorting events by descending date, and ascending time if multiple events on a date

UPDATE: Solved with the answer below. $past_events = array(); $past_events_sql = $wpdb->get_results( $wpdb->prepare( "SELECT p.ID, from_unixtime(m.meta_value,'%%Y-%%m-%%d') ...
Jen Abella's user avatar
1 vote
1 answer
297 views

How To Fix WP Query Returns Results But Shouldn't?

I have a WP Query that should return no results, but instead seems to be returning items. I'm guessing the null result is being interpreted as "return all results" but I'm not sure the ...
opendatum's user avatar
0 votes
0 answers
16 views

How to query all posts in CPT + only posts with custom tax in another CPT?

I have 2 post types. Both use the same custom taxonomy. How can I create a query that will display; All posts of CPT1, and All posts of CPT2 that have a taxonomy. Is this possible with a single ...
Michael Rogers's user avatar
1 vote
0 answers
62 views

WP_Query orderby author__in

I use WP_Query to get author posts with author ids array order. But it is not getting with true order. $user_ids = array( 10, 11, 12, 13 ); $args = array( 'order' => 'DESC', '...
wpuzman's user avatar
  • 111
1 vote
1 answer
262 views

Nearby locations using Advanced custom fields, maps?

I am looking for a solution to query nearby locations based on a given lat and lng value, using ACF maps field. All I currently have is a lat and lng search value (that I want to use to search for ...
RobbTe's user avatar
  • 242
0 votes
1 answer
210 views

WP_Query - display posts by custom field and order by another

I have custom WP_Query call where I want to display CPT by one custom field and order them by another: $args = array( 'post_type' => 'nehnutelnost', 'post_status' => 'publish',...
Juraj's user avatar
  • 144
0 votes
1 answer
59 views

set object terms after some some time of published post - functions.php

I have to change the published post in one category to another category after some days. I have created the below code for the function, which I have added in the functions.php file in child-theme. ...
praba's user avatar
  • 13
0 votes
1 answer
158 views

Get next and prev item from custom WP_Query and Custom Post Type

I want to make a pager for a custom wp_query where I can have a prev and a next. I have a CPT called family and I must show the families that meet the condition that their status is Retained, ...
dexter's user avatar
  • 1
0 votes
0 answers
136 views

Block internal search queries with pre_get_posts and regex rules

This relates to my previous question: Internal search spam (UPD: I no longer use Ivory Search) The closest question I found: Block search keywords As I understood, I need to use pre_get_posts, but I ...
Terry's user avatar
  • 1
0 votes
1 answer
67 views

What's the best way to make a blog page on Wordpress?

I understand we can use WP_QUERY and search for posts with the word blog on it and then loop the results, but that probably isn't suitable for production, because it will lead to bugs, so I am ...
Sayaman's user avatar
  • 135
0 votes
0 answers
44 views

Use get_pages() before another plugin modifies it

In my little plugin I am using get_pages() to get some specific pages. Important is the usage of "child_of" and a custom field key. $pages = get_pages([ 'child_of' => 206, //Gets ...
Timo's user avatar
  • 1
1 vote
1 answer
372 views

Order by slug in get_terms with multiple taxonomies

I am builing a search engine where I need to search in 2 different taxonomies and sort them by slug. I got this code to do so. $search = sanitize_text_field( $_POST[ 'search' ] ); $content = ''; $...
Mastafu's user avatar
  • 45
1 vote
1 answer
627 views

Get posts for which a custom field is not present, with get_posts

I'd like to get all posts for which the custom field hidden is NOT present. This does not work: $postsForSitemap = get_posts(array( 'numberposts' => -1, 'orderby' => 'modified', '...
Basj's user avatar
  • 85
0 votes
1 answer
889 views

get_the_ID() in the footer returns wrong value

I'm using get_the_ID() in footer.php but it returns a wrong value. It might come from any of the plugin which is altering The Loop without resetting it after with wp_reset_postdata() as mentioned in $...
Basj's user avatar
  • 85
0 votes
1 answer
823 views

How to Get The Taxonomy Term in Custom Post Type Loop Inside a Wp Query

I need to get the term of each post while running WP Query. I tried this inside the loop $term = $loop->get_queried_object(); echo $term->name; but I am still getting custom Post Type ...
Behseini's user avatar
  • 525
0 votes
0 answers
124 views

Multiple nested meta queries

This has been driving me nuts for days so if anyone can provide any sort of solution that would be lifesaving. I have a form that is querying posts (WP_Query), depending on the meta data. Form fields ...
Josh's user avatar
  • 1
0 votes
0 answers
76 views

WP_Query for distinct meta values

Is it possible to construct a WP_Query in such a way that once a (ACF) meta value exists on a post in the query the subsequent ones cannot contain this value? For instance if I'm querying countries, ...
Fluxian's user avatar
  • 130
0 votes
0 answers
47 views

Query post ordered by meta value that show first post that contained a tag

I have a query post for my CPT 'listing' that order posts by value of price contained on meta key. Now I'd like to add the possibility to show in the loop first posts that has a specific tag (o ...
Giulio's user avatar
  • 51
0 votes
1 answer
52 views

Group Product Types

I am using Advanced Custom Fields and I am attempting to group together the custom post types with a similar value from a dropdown field. As an example. Other would-be its own heading and projectors ...
Ryan Hammond's user avatar
0 votes
1 answer
46 views

Nested Queries of decreasing specificity

I have the goal of getting n custom posts from a query. I have 4 values stored in ACF. If I can find n posts where all these values are the same as the current post's, then I want to return those n. ...
Fluxian's user avatar
  • 130
0 votes
1 answer
39 views

Wp-query Order By problem

I'm trying to sort a query according to the order they write it in but it takes an order by ID. The variable $idpaginas prints: 20659,20626,20585,20616,18464,19748,19991,18520,20588,21268,18753,20556,...
Marcel CL's user avatar
0 votes
2 answers
238 views

Conditional sorting with variable using WP Query

I have for example this posts in WP: Name ID Date JohnA 6 01012020 JohnB 7 01022020 KateA 7 05052021 SamA 4 01022020 SamA 4 01022022 How I can order by date, but also put posts with ...
Horhe Garcia's user avatar
1 vote
1 answer
413 views

Wp_query function to search from product_title 'OR' product tags name

I am looking to show search results from either product title or product tag name. I have implemented the product title search through the below code, but I need to add tag name search also into it. ...
Dhruvbhati's user avatar
1 vote
1 answer
1k views

Output an array of terms for a 'tax_query' => array()

I'm trying to use custom fields on the backend to set the taxonomies in a WP_Query for a category archive on the front end. In the page template. this gets my categories from the custom field: $terms =...
BlueDogRanch's user avatar
0 votes
0 answers
145 views

duplicated posts when using pagination

This is my query, it's so simple (the query is generated by canvas plugin) ps: the $page has correct value $query_var = [ 'post_type' => 'new', 'orderby' => 'date', 'order' => 'DESC', 'paged' ...
Мохамед Русланович's user avatar
1 vote
0 answers
17 views

Wordpress Pagination changes my template

I have a problem using pagination for terms in my custom taxonomy, let's call it Case-Studies. If i go to /insights/page/2, posts will be displayed correctly, and I can navigate between pages. The ...
Calin Diea's user avatar
0 votes
1 answer
541 views

How to _GET multiple value checkbox WP_Query in Custom Toxonomy / Custom Fields

I try to make a sort of fiter for my website. Goal is for the visitors to query results by prices ('prix') and hobbies ('aimerparlapersonne'). Prices are numbers between min and max. Hobbies is ...
frontcodelover's user avatar
0 votes
1 answer
24 views

Create a loop on my pages with new "WP_Query"

I wanted to loop through these four pages. Basically I would like my loop create a "li" by "page_id". I just know this is from my "new WP_Query" which is not good. How ...
Maximus's user avatar
0 votes
0 answers
229 views

Make a products only viewable to a specific user ID in meta_query pre_get_posts

I need to show some products to specific users set in the product itself by an ACF field that stores the user ID. I want to hide the product from the product category page / shop completely unless ...
Jake's user avatar
  • 69
0 votes
4 answers
80 views

Trouble inputting variable into WP query

Not sure the best way to describe this, but basically I am defining a variable ($cat) which chooses a taxonomy based on a number defined just before the query is called, but as the number is defined ...
ukijake's user avatar
  • 11
1 vote
1 answer
31 views

Take all produts by category

I don't know why i can't take the products by category name. I get no product found. The code look like this <ul class="glide__slides"> <?php $args = array( 'post_type' ...
Digital Point's user avatar
0 votes
0 answers
33 views

Why when I using infinity scroll the one post loads over and over?

I am using the following code to make my posts infinite loading. But it's weird, for now there are 7 posts on the site, and 6 posts setting for displaying and when I started scroll only one post ...
Victor Sokoliuk's user avatar
0 votes
1 answer
2k views

WP_Query orderby not work with meta_key

I want to order the post by 'leasenum' in my archive-shop.php. I want to filter the specific 'mall' . The result set is correct but the order is wrong. The orderby only works if I remove the 'meta_key'...
Muffin's user avatar
  • 1
0 votes
1 answer
91 views

Get All posts by Tag_Id not working, query seems to contain extra term_taxonomy_id

I have the following simple query $args = array('posts_per_page' => 7, 'tag_id' => 43, 'post_status' => 'publish', ); $q = new WP_Query($args); echo ($q->request); // ...
shelbypereira's user avatar
1 vote
1 answer
2k views

Custom meta_query order for Elementor based on post meta key [closed]

I'm failing at writing an Elementor $meta_query function so posts will be ordered by meta_value_num of a given key. Each post has a numeric value for the key google_unique_page_views My example is ...
JVAN's user avatar
  • 23
1 vote
0 answers
489 views

wp_query 's', search filter with pagination is not working

I made this shortcode for a page of posts. I want to set a search function. I filled for example: "web design". The search-result will set in the var "$catSearched". Then it works ...
Jungolmok's user avatar
0 votes
1 answer
179 views

After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel

Made s script that under certain conditions adds a new custom post to the database. All works fine. But there is a flow. After writing the post to the database with my script I can not extract it with ...
Mihail_OLARU's user avatar
0 votes
0 answers
100 views

Create if else for post types in WP_Query 'post__in' values

I'm trying to enable users to select individual posts by custom post type using a new WP_Query $posts = new WP_Query( array( 'post__in' => selected_posts(), 'post_type' =&...
Brad Dalton's user avatar
  • 6,916
0 votes
0 answers
119 views

Facing problem with tax_query results

I need to get search results for posts on the basis of post-category(must) and posts-tags(optional). The process is like: search for a string e.g. "bananas" the category is always static ...
Majid A.'s user avatar
5 votes
1 answer
416 views

Is there a way to extend WP_query so Custom Post Types can have properties?

Having trouble finding info on this. When working with lots of metadata/custom fields, I would really prefer to simplify getting the meta data inside of templates instead of using get_post_meta and ...
liquidRock's user avatar
0 votes
0 answers
97 views

How do i create a custom post query when the meta value is an array?

A number of properties have been imported from an external API and saved into a custom post type called 'Properties'. I want to filter these properties by the city they are located in, however it is ...
Zeus7's user avatar
  • 1
0 votes
0 answers
337 views

wordpress pagination wont render on custom page template even though its right under the loop like the documentation says so

In Wordpress how do you get pagination to render on a custom page template? https://developer.wordpress.org/themes/functionality/pagination/ Examples #Examples Loop with Pagination #Loop with ...
kawnah's user avatar
  • 123
0 votes
1 answer
34 views

How to not display tags with less than X posts

Is there a way to avoid displaying tags which have less than X Posts? the answer here is close Remove from Google Tags with less than 2 posts however it suggests to send a respose header to google. I ...
shelbypereira's user avatar

1
6 7
8
9 10
115