A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

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
4
votes
2answers
4k views

meta_query where value is equal to given value

I currently have this custom query which I am trying to filter the product (paintings) by artist. $artistID = $_GET['artist_id']; $args = array( ...
1
vote
1answer
13 views

Import wp users via one click demo option

I have created a WordPress theme and added an option to import demo data in which I have added WordPress posts, pages, customize options. when my client buy the theme and use one-click demo option to ...
0
votes
2answers
431 views

How can I show only last year posts in wordpress archive?

I am using Wordpress archive widget to display archives of My WordPress site. But there is a condition, I want to display only last year archives, not this year. I am using inbuilt widget, so what can ...
1
vote
1answer
26 views

Need wp_query to return all children and grandchildren

I am working on a site with three different main 'topevel' sections, that act as the top level parents of the site. Each toplevel section has children and grandchildren, and there needs to be a ...
1
vote
2answers
2k views

Two loops on archive page

I have 2 loops on the archive page. I want the first loop to display the 2 last posts of the category and the second loop offset 2 last post! <div class="top-posts"> <?php if (...
4
votes
2answers
58 views

How to get random posts and order them by date

I need to get some random posts and order them by date. To get random posts I used the following: $query = new WP_Query( [ 'post__in' => $post_id_array, 'posts_per_page' => $...
1
vote
1answer
22 views

Display CPT posts based on specific taxonomy

So I have a custom post type called opencourses. There is a custom taxonomy called typ. Obviously inside I have a multiple terms divided into two main pillars (production and services). ...
1
vote
1answer
584 views

How to properly reset a nested WP_Query query

I'm missing something here. What's the proper way to reset a query so that it doesn't interfere with any other queries it may be nested in? This is the kind of result I'm going for: Main page ...
0
votes
1answer
1k views

Only show current category post

I have created a custom loop using WP_Query to show posts associated to a custom post type I created. <?php $the_query = new WP_Query( array ( 'post_type' => 'scp_content' )); ?...
1
vote
1answer
36 views

Wordpress pagination not working using WP_Query

Ok I know there are a lot posts on this already but I'm not able to find what is wrong with my code. Because pagination is still not working. The weird thing is the same code and template works fine ...
2
votes
1answer
102 views

Order by two meta keys

I have this code which works fine: $args = array( 'post_type' => 'brands', 'meta_query' => array( array( 'key' => 'br_type', 'value' => 'Aviation' ...
1
vote
1answer
716 views

WP_Query: include custom post type only with specific meta value

I have the following arguments for a WP_Query: $args = array( 'post_type' => array( 'cpt-1', 'cpt-2' ), 'post_status' => 'publish', 'posts_per_page' => 9, 'meta_query' => ...
2
votes
1answer
33 views

How to add another parameters to WP_Query?

I need to do something like that: $postsOrder = get_sub_field('posts-ordering'); if ($postsOrder = 'post_views_count') { $queryPopular = array ( 'meta_key'...
1
vote
0answers
49 views

meta_query BETWEEN, but the range is stored in the custom field

I've seen plenty of samples of using meta_query to find if the value is between a range, where the range looks something like this: $meta_query_args = [ 'key' => "custom_field", 'value' =...
0
votes
1answer
741 views

tax_query showing no results

I'm creating a music database site with two custom post types: tracks and albums. I've linked the tracks to their respective albums with a custom taxonomy for the album's slug. On each album page, I'm ...
1
vote
1answer
35 views

WP_Query tax query part of slug

I have problem with filtering post with tax query. I have a custom taxonomy called 'actors' and example of the slug is 'david-hasselhoff'. The problem is the post is found when I search with 'david ...
1
vote
1answer
469 views

Excluding pages in WP_query using ACF

I have a custom loop for showing child pages of the current page, but I'd like to allow the WP user to enter page IDs to be excluded from the loop, using Advanced Custom Fields. My current loop is as ...
0
votes
3answers
707 views

wp_query get data from advanced custom field in wordpress

I want to get the data from advanced custom field using wp_query from another custom post type: $title = get_the_title(); $the_query = new WP_Query( array( 'posts_per_page'=>9, '...
1
vote
1answer
2k views

Query custom post type by custom taxonomy (category slug)

I've followed several related solution. But I'm still facing the problem. I've applied the following code for my custom post query by taxonomy (category). But it's not working. I think my problem with ...
1
vote
0answers
20 views

WP_Query search posts by custom post type and custom taxonomy

I have custom posts articles with custom taxonomy tags-articles, I need search all posts with have the term in title, or taxonomy associated with same title (or partial title): Example os published ...
0
votes
1answer
484 views

Filter custom WP_Query by first letter of a custom field - hopefully using Search and Filter Pro?

I have a custom WP_query that very simply filters a custom post type: <?php $query = new WP_Query( array( 'post_type' => 'professionals', 'search_filter_id' => '204' ) ); ?...
2
votes
1answer
446 views

Revolution Slider Orderby Two Custom Fields

I have create Revolution Slider which load the custom post type, Events. There are two custom fields, Event Start Date and Event End Date. I would like to display order by Start and End date. Because ...
2
votes
1answer
1k views

How to get a category in a list item class

I am need to know how would I get the category to be dynamically input in a WP_Query This is the code I am using: <li class="<?php the_category(' ')?>"> but the output is breaking. ...
0
votes
1answer
4k views

Action hook “wp_insert_post” works but not for last imported post

I want to run a custom function whenever posts are imported to my custom post type. I am currently running this code - function on_post_import($post){ global $wpdb; $results = $wpdb->...
0
votes
0answers
17 views

Meta_query on same meta key, with diffrenct values

i'm trying to get_users with the meta_query where i need to find users where either they don't have the meta key, or it is blank. It seems like everywhere i look, i should be able to use the OR on ...
0
votes
0answers
23 views

wp query search multi terms

i have this code it work perfect if i search for 1 term but when i add 2 terms to search it fail protected function process_item ( $data ) { try { $data = array_map ( 'trim', $data ); ...
1
vote
0answers
26 views

Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?

Short version: I am wondering if the default WP loop (for example in a rather simple index.php) is supposed to return custom posts belonging to a custom taxonomy when the URL is something like https://...
1
vote
1answer
1k views

how can I override The Events Calendar query modifications?

I am implementing some special search options that should exclude anything not of the type post. The Events Calendar is interfering and modifying the query on the fly anyway. My query mod just looks ...
1
vote
1answer
19 views

Function get_queried_object() return NULL in custom taxonomy

Hi i need get term ID from custom taxonomy but it is always NULL. taxonomy-galerie-kategorie.php <?php /** * A custom taxonomy template for gallery. */ ?> <?php ...
1
vote
1answer
22 views

How to restrict the search fields for a specific post type

How can I restrict the search for a specific post type? I am using the following code in functions.php: function searchfilter($query) { if ( is_admin() || ! $query->is_main_query() ){return;}...
0
votes
1answer
480 views

Pagination not working on homepage

I tried multiple solutions but its not working. When I go to /page/2, it doesn't work. I'm executing custom query in index.php of my theme. if ( get_query_var('paged') ) { $paged = get_query_var('...
0
votes
1answer
2k views

Get random terms

Is it possible to get random terms? To get random posts you could use WP_Query and set 'orderby' => 'rand'. But is there any way to do that with terms? I've tried this: $terms = get_terms( ...
1
vote
0answers
20 views

How to verify wp user password by sql query in wp? [closed]

I want to verify the user password without function only by the SQL query.
1
vote
0answers
23 views

Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?

I am trying to embed a custom WP_Query inside a shortcode I have activated on one of my pages (created in Elementor). I have a Custom Post Type called 'inspector-profiles', and for some reason when I ...
1
vote
0answers
18 views

creat filter with wp_query

I doing make a filter with wp_query for a custom post type. I create my page and I want to include a filter by date (year) with wp_query <?php get_header(); ?> <div class="row"> <...
1
vote
0answers
24 views

Can we return all category (not post) with Custom Query Filter? [closed]

I wanted to make some sort of category grid using elementor's Custom Query Filter. I will have a featured image and and post title. I know ways to do it with a loop but that will be not applicable ...
0
votes
2answers
595 views

How To Call WP_Query From A Subdomain?

I have a PHP script running in WordPress, that uses a WP_Query to get the posts from one of my subdomains and return it as a JSON string. The script only receives the post data if I call it using the ...
2
votes
1answer
24 views

SQL User Query by Multiple Roles using PHP

I can successfully get all my WordPress users using the following code: global $wpdb; $sql = 'SELECT * FROM ' . $wpdb->users; $users = $wpdb->get_results( $sql, 'ARRAY_A' ); However, I need to ...
1
vote
1answer
525 views

Find all product that contain terms with %keywords% in WP_Query

I want to use WP_Query to find all product terms entered in the input field. Here is my WP_Query code. $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args = array( '...
1
vote
0answers
13 views

Troubles with acf/save_post and WP_Query

I made an accounting system with ACF and CPT, but my client wants to be able to see the balances of each account from the post table in a column and not entering the single of each account. My ...
0
votes
1answer
444 views

Sorting meta_value as integer doesn't work

This plugin uses the below chunk of code to print the top 10 highscores. But this doesn't get the list of top 10 scores sorted by meta_value in my WP install $scoreboard = new WP_User_Query( array( ...
3
votes
2answers
444 views

Extending WP_Query — Optimise SQL query

I'm storing posts, a user follows in a custom table that has the columns id, post_id and user_id. To fetch posts that a user follows I have extended the WP_Query as follows: class ...
0
votes
1answer
15 views

wp_query get the 2nd post

How could I get only the 2nd product in this query? $loop = new WP_Query( [ 'post_type' => 'product', 'posts_per_page' => 1, 'meta_key' => '...
1
vote
1answer
438 views

Hiding taxonomies with no children WP_Query & tax_query

I have this code which has taken over 7 hours to put together through research but the last hours or so I have hit a brick wall! I require the taxonomy title to be hidden if there are no posts ...
0
votes
1answer
18 views

WP_Query arguments order

Given the following example of a custom query $query = new WP_Query(array( 'posts_per_page' => 7, 'categor_name' => 'events', 'offset' => 5 )); Does the order of arguments ...
-1
votes
3answers
5k views

How add class the_content();?

How do I add a class the_content();? <div class="csoporszoveg"> <h3 class="csoporcim"><?php if ($settings['enable_link']) { echo '<a href="' . get_permalink($...
0
votes
1answer
20 views

Need to show 7 posts from actual date

I have specific category, in what I have a lot of posts. Every post starts from, for example 21 october 2019. I have this code to show posts in the correct sequence: class GoroskopController { ...
1
vote
0answers
11 views

A method for ordering mixed dates in search result loop (theory only, no actual code)

My issue Hello, some time ago: I had the regular post and the custom evento post types; the evento post type had a ev_data_out custom field; the search result loop had to return a list of posts from ...
0
votes
2answers
931 views

Return custom product in ajax call loop

Working on Wordpress / Woocommerce architecture, I'm new in woocommerce, before i've worked on django and laravel framework, the project is a plugin wp, where a little form is fit with select tags ...
0
votes
0answers
9 views

Restrict access to certain pages

I have a custom /search-results/ page. I would like users only to have access to that page once they have submitted my custom search form and if they do try and access it directly they must be ...