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
37 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( ...
0
votes
1answer
12 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() ) : ?> ...
-1
votes
1answer
32 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 ...
0
votes
1answer
15 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 ...
1
vote
2answers
40 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( ...
1
vote
0answers
20 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') ...
-1
votes
1answer
11 views

Post Per Page showing 2 posts

i need to add just a one post in index.php. But if i add post_per_page => 1 they get two posts https://i.stack.imgur.com/2POSx.png https://i.stack.imgur.com/ruAiW.png
1
vote
1answer
25 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 ...
0
votes
0answers
16 views

Replace a single variable with add_filter

I'm trying to hook to a function in class-wp-query.php and replace a single variable – $searchand = ' AND ' into $searchand = ' OR '. The trouble, I assume, is that it's only the third occurence of ...
0
votes
0answers
13 views

How do I compare the value of two taxonomies in a wp_query

How do I, in a wp_query, get all the posts where 2 taxonomies do not have the same values? for example i have a taxonomy of widths and one of heights and I want to, for one query, pull all the posts ...
0
votes
0answers
11 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 ...
1
vote
0answers
16 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', '...
0
votes
0answers
14 views

Updating custom query var with multiple values

I'm using set_query_var to bookmark snippets that were already published, in order to exclude them from other independent loops on the page. Basically, so that no title ever comes up twice. Basically ...
0
votes
0answers
20 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 ...
0
votes
1answer
15 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',...
0
votes
1answer
24 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. ...
0
votes
0answers
21 views

search through "product title" using WP_Query?

I am trying to get related products and filter them by if title contain similar words example products title: black shirt size M black pants size M <?php global $post; global $wpdb; $related =...
0
votes
1answer
18 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, ...
0
votes
0answers
26 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 ...
0
votes
0answers
24 views

While loop in functions.php outputting the_title() of each post on frontpage

I have the following code on the website: $args = array( 'posts_per_page' => -1, 'post_type' => 'gyorshirek', ); $loop = new WP_Query( $args ); $wp_query = $loop; if ( $loop->...
0
votes
1answer
34 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 ...
0
votes
0answers
37 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 ...
1
vote
1answer
21 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 = ''; $...
0
votes
0answers
20 views

Change search query in wordpress custom post type

I want to change the query of search a custom post type in wordpress admin panel. I use this method: function change_admin_search( $query ) { $post_type = 'custom_post_type'; if( ! is_admin()...
1
vote
1answer
62 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', '...
0
votes
0answers
7 views

View list of custom posts within a date range relative to today's date, based on a custom date field

For example, I would like to display all posts with a custom date field that are between 5-10 years old as of today. I would like to be able to view this anytime and have it always show 5-10 years ...
0
votes
1answer
25 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 $...
0
votes
1answer
19 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 ...
0
votes
0answers
19 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 ...
0
votes
0answers
22 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, ...
0
votes
0answers
42 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 ...
0
votes
1answer
13 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 ...
0
votes
0answers
29 views

Wordpress Ajax form filter | Search by title with ajax form, breaks the other filters

I have implemented a form within my code that gives the user the possibility to filter the products according to his needs. The form was created in ajax, to increase the user experience level of the ...
0
votes
1answer
36 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. ...
0
votes
1answer
29 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,...
0
votes
0answers
26 views

get different meta-data of a complicated query at the same time

I have a function that generate a very complicated query with meta_query, tax_query etc. and now am using it in a filter page. i need to fill the filter page by some meta data, like number of paied, ...
0
votes
2answers
102 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 ...
0
votes
0answers
18 views

how to display recent post by category on home page

hi I m new in WordPress i want to display recent posts based on categories like this I found the following code but it seems not to work for me. here is the code function wpb_postsbycategory() { // ...
0
votes
0answers
18 views

Wrong pagination results, page counter resets when navigating

I have a custom loop that shows products according to a given criteria, e.g Products from a particular state, category or general product name search. This is in a page on my website. The problem is ...
1
vote
1answer
24 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. ...
0
votes
0answers
7 views

how to show comments only author which send own posts in wordpress

I am trying to make things work like where author can see only them post comment in admin comment section . While admin should have all permission. I am having author's post comments in comment ...
1
vote
1answer
14 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 =...
0
votes
0answers
81 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' ...
1
vote
0answers
12 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 ...
0
votes
0answers
24 views

Passing a SQL query to the WP Query

I'm writing this filter and would like your help in fixing the following this code. I will like to take the SQL statement below and place it in a WP query. select post_id from wp_postmeta WHERE ...
0
votes
1answer
50 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 ...
0
votes
1answer
16 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 ...
0
votes
0answers
18 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 ...
0
votes
4answers
32 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 ...
0
votes
0answers
11 views

Unrelated post showing in WP_Query

Good day. I have a simple WP_Query that I am expecting to have a blank data but somehow, it is fetching unrelated post values. $tagId = get_tag_ID('test'); $args_news = array( 'post_type' => '...

1
2 3 4 5
110