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
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
24 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
25 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
25 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
534 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
14 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
446 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
449 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
957 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 ...
3
votes
2answers
120 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
50 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
550 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
37 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
24 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
513 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
24 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
155 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
24 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
550 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
431 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
480 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
39 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 ...
1
vote
1answer
21 views

List posts in a given category

I am using this code to get all posts sorted alphabetically in a given category, it works, but I feel the code can be improved... <?php $cats = get_categories('include=5'); foreach ($cats as $cat) ...
0
votes
1answer
462 views

Use not custom fields in get_posts() meta_query?

Is it possible to use not custom fields in get_posts()'s 'meta_query' to use a or-relation statement with a custom field and a category id? Like this: $args = array( 'posts_per_page' => 6 ...
0
votes
0answers
41 views

How to sort by multiple values in a nested WP_Query

I am displaying courses, enrollment, along with rooms whose capacities are greater than or equal to the enrollment. This query works, except the 'order' => 'DESC' for courses, and 'orderby' => '...
0
votes
1answer
45 views

How to show all taxonomies within custom post type loop

I am trying to show all records for a particular custom post type and I want a list of all taxonomies in a dropdown. Here is the query for the CPT: <?php $articles = new WP_Query(array( ...
6
votes
3answers
30k views

How to use the_posts_navigation for wp_query and get_posts?

WordPress have the_posts_navigation function since 4.1.0. But I don't know how to use with wp_query or get_posts. the following code is in a template file of page.wp_query method: <?php if ...
1
vote
1answer
24 views

How to use offset in WP_Query

Where do I put the offset function? <?php $args = array( 'post_type' => 'post', 'category_name' => 'category', 'orderby' =&...
1
vote
2answers
658 views

merge two query arguments into one WP_Query call

I'm overriding WooCommerce's default search query to include searching by SKU as well. // default search query $query_default_search = new WP_Query( array( "post_type" => "product", ...
0
votes
0answers
43 views

Custom Query - exclude child category post from parent category post loop

I'm trying to change the way wordpress displays posts under category pages. Ex: Cat1 (contain 1 post) Cat2 (contain 1 post) Subcat2 (child of cat2 contain 1 post) Cat3 (contain 1 post) In the ...
0
votes
2answers
485 views

Extending WP Query: Custom geolocation meta values work, but tax_query breaks

I've built a custom query for geolocation searches. I'm saving lat and lng within each custom post type as a meta value. My query extension returns results successfully when lat and lng are the only ...
1
vote
1answer
440 views

Filtering out child category posts from parent category archive not working

In this example cat 5 is the parent category, and 42 is a sub-category. I the main category 5 archive I don't want any posts from sub-category 42 displaying. Why isn't this working? function ...
0
votes
0answers
31 views

Adding nofollow to all the post links in get_posts with pre_get_posts or WP_Query

Can it be done with pre_get_posts in functions.php file to change the output by get_posts queries on blog/site. I found nothing about adding html attribute to anchor tag here: https://developer....
1
vote
2answers
528 views

How to add post_distinct filter to WP_Comment_Query?

I want to fetch a list of posts with the most recent comments. However I don't wish to simply get the latest comments and have duplicate posts, but I want to group the posts (by their ID). I tried the ...
0
votes
1answer
505 views

Moving the array pointer inside a WP_Query while loop

How can I move the pointer ahead a place, or at least offset it, as I'm trying to pull two posts during each loop of the while loop? I've indicated where in the loop I would like to move the pointer: ...
20
votes
1answer
5k views

Some doubts about how the main query and the custom query works in this custom theme?

I am pretty new in WordPress theme development and I'm not so into PHP (I came from Java and C#) and have the following situation in this custom theme As you can see in the homepage I first show a ...
1
vote
1answer
517 views

Loop returning only 1 result

I am not sure as to why when I run my loop only 1 result returns. Here is my code: <?php if ( is_front_page() && twentyfourteen_has_featured_posts() ) { // Include the ...
0
votes
1answer
3k views

Is it possible to add query parameters on the archive page?

I have a custom post type 'Works', and an archive page 'archive-works.php'. I would like to hide the non-public posts from the archive page, so I added a custom meta box. I also modified the query to ...
1
vote
1answer
111 views

Get all post IDs from current WP_Query - not just currently visible

I want to get all post IDs from the current query. I know how to get all IDs of the current page using the following: global $wp_query; $post_ids = wp_list_pluck( $wp_query->posts, "ID" ); This ...
1
vote
1answer
94 views

How to use WP_Query to filter posts modified after a specific date

I'm looking for a way to get all posts modified after a specific date, but still couldn't find an answer for that online; All websites says that this is still not supported until now. Is querying ...