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
8 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
416 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' ) ); ?...
0
votes
0answers
11 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'...
2
votes
1answer
416 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
11 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
21 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
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
21 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
0answers
17 views

problem by deleting new plugin installed inside the WordPress after any heroku app sleeping

I have installed this repo inside my Heroku app as you can see here: https://ss-wp25856.herokuapp.com By user id: ss and password (for more information to check or log needed): n6RF1TSNrNkA!%...
1
vote
1answer
62 views
+50

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')),'posts_per_page' => -1,'meta_key' =&...
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
17 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
20 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
479 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
19 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
15 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
17 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
11 views

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

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
573 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
22 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
451 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
11 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
22 views

WP_Query tag can't find part of slug

I have a custom post type called movies and each movies has tag(s) with the name of the actors. Recently I am trying to allow user to found posts through entering actors' name. This is what I have ...
0
votes
1answer
437 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
434 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
13 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
422 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
16 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
18 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
10 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
678 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
8 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 ...
3
votes
2answers
118 views

retrieve thumbnail from post ID of best selling product in category

The code below displays product category names, links and their thumbnails on hover. The thumbnails ($image) retrieved are those manually set via the woocommerce product category menu. I am trying ...
1
vote
1answer
45 views

How to change posts order on Category and Tag archives?

WordPress by default order posts in descending order by date. But I want them to be in ascending order by date. How do I turn the order to ascending only for tags and category? I don't want blog post ...
2
votes
1answer
529 views

How to count data records in wordpress which have same meta_value in wp_postmeta table?

I want to get number or count of same meta_value of meta_key == 'parent_id'.How can i get it? What should be the wordpress query for counting records in same table? //set the meta_key to the ...
0
votes
1answer
25 views

How to print term name inside wp post loop

I have 3 different taxonomies in a custom post type. I want to print all posts with term name with them. for example: taxonomy 1 =>taxonomy=banks&post_type=creditcards taxonomy 2 =>...
0
votes
1answer
22 views

WP_Query by MAX post_id?

I am trying to get the latest inserted post_id by an author using wp_query class. I have to use MAX(wp_posts.ID) in the args of the query i use. Is this somehow possible using wp_query class or do i ...
0
votes
1answer
492 views

Comment count same for every post in homepage WP_Query

I have a WP_Query on my homepage template that works just fine for get_the_title() and MANY other functions for each post in the loop. However, any way of getting the comment count just grabs the ...
1
vote
0answers
16 views

Use posts_groupby filter with part of string in wp_query?

I am using posts_groupby filter to group by a custom field my wordpress posts. Is there any way using wp_query and posts_groupby to group my posts using part of a string of the custom field? Any help ...
0
votes
1answer
17 views

Individual months in WP Query

I would like to create WP_Query query and I am using date parameters. How should I should write my query if I want to get all posts from: January 2019 and May 2019 (there is not range).
-1
votes
1answer
120 views

Stop all SQL_CALC_FOUND_ROWS wordpress queries

In phpmyadmin I often see this query that hangs with a status of "sending data": SELECT SQL_CALC_FOUND_ROWS wp2a_posts.ID FROM wp2a_posts WHERE 1=1 AND wp2a_posts.post_author IN (1) AND ...
1
vote
0answers
23 views

How to use the query hook/filter?

I want to stop this query from running: SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_author IN (1) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = '...
0
votes
1answer
546 views

Custom Search Query – include only custom fields and title

I have a custom post type and I also need a custom search. I want the post title and two custom fields to be indexed/queried. I found solutions for title only and for custom fields but not for both so ...
0
votes
1answer
427 views

Mathematical operations on custom field values? (updated)

I'm attempting to write a function, run by a cron schedule at midnight every night, that will subtract 1 from the integer value of a custom field. It will function basically as a countdown timer for ...
0
votes
1answer
466 views

Manually build WP_Query

I'm trying to manually build a query in 'loop.php' that outputs a list of 3 posts from a custom post type above the results automatically given when doing a search in WordPress. As such, I've got the ...
0
votes
2answers
36 views

use mysql variable in a $wpdb->query to reindex a column?

I have this MySQL query, which do work in PHPMyAdmin: set @ROW = 0;UPDATE `wp_wpsstm_subtracks` SET `subtrack_order` = @ROW := @ROW+1 WHERE tracklist_id='176226' ORDER BY `subtrack_time` ASC I would ...