The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
2answers
21 views

how to pass args for archive.php query?

I am trying to pass args to archive.php so that I can order the posts, set the number of posts, etc.. but the query is done like this <?php if (have_posts()): ?> <?php while (have_posts())...
0
votes
1answer
22 views

How to get the latest post list (of the parent custom custom type)

I am looking for a solution to get the latest list of custom parent posts. example: Post A Child Post A Child Post B Child Post C The bold list items are the posts/pages I want to retrieve. I ...
0
votes
1answer
37 views

Select multiple categories with is_tax

i have a good function for exclude out of stock products from category. The problem is i want exclude for more than one category (really i want show only in one category, but i think this is the way. ...
0
votes
0answers
47 views

how to retrieve specific product attribute value in an sql query?

I am looking for some suggestion on how to run a query on wp-term with multiple "same column name as different attribute name" bottom line I am trying to query woocommerce products + all their ...
0
votes
1answer
31 views

Query custom post type and custom field by URL parameters

I have a custom post type staff. and a custom field alphabet for posts in that post type. Each staff will be assigned to a letter either A or B ... Z based on the first letter of the staff's name. On ...
0
votes
0answers
50 views

Post Type Search Gives Unexpected Results

I am working on a WordPress site that has several custom post types. Of course this lends itself to writing a custom search form. However, the results from test searches have been less than ...
0
votes
2answers
17 views

How to get only present and past posts with post_date

An administrator wants to make posts for a future date but not visible for visitors. The posts come from a custom WP_Query inside my plugin so the basical WP behaviour does not work in this case. I ...
0
votes
0answers
18 views

How to get user avatar via WPDB

For my REST-API i need to get for every post the username, date ... and Avatar ! $query ="SELECT POST.ID, POST.post_title, POST.post_date, USER.user_nicename FROM wp0x_posts POST INNER JOIN ...
0
votes
0answers
21 views

match and update acf fields with array values

i created array from gravity forms entries that has information about students payment. this array contains only the values i need about payments. $arr: [6047] => Array ( [0] ...
1
vote
1answer
21 views

WP_Query To call data from diffrent tables

I need to retrieve data from multiple tables , wp_postmeta to get posts with a specific type ( question ) , wp_user for author informations and also wp_comments . I need those information to use them ...
0
votes
0answers
19 views

WP query custom search by meta query nested ACF repetear field Group > Repeater

So I have searched the web but didn't found quite an good solution to this problem. I am having nested ACF field with a repeater inside a group and I want to display and order wp query by that item ...
1
vote
0answers
12 views

Wordpress custom post type with meta - how to retrieve with wp_query

I developed simple plugin and now would like to get only posts where start_date < $now & end_date > $now so I have to add meta_query to the args but how should it look like? $args = ...
1
vote
1answer
15 views

Get a list of posts with associated meta_value

Recently I began to use the Custom Fields. I would like to display a listing of posts which contains the meta_key "oldtimer" and also get the corresponding meta_value. Here is the expected result: &...
0
votes
1answer
14 views

One of two similar WP Query is very slow

I have two WP Query are very similar. one is fast and another is very very slow. I have already test two query via mysql directly. the fast one: SELECT wp_posts.* FROM wp_posts INNER JOIN ...
0
votes
0answers
8 views

in WordPress Loop update_user_ meta with Current Month and Year as Meta_Ley

I am making a page for my wordpress authors to see there stats. For the same, i first loop through all author ids, then i loop through all of there posts, and sum the post views meta key for all. I ...
0
votes
1answer
46 views

unique post in “$args” of wp_query display more than one post

I can't find the rights arguments to display only one post of a category when I click on a div. I call the post with Ajax and I display it in a div popup.Perhaps these arguments are not sufficient, or ...
0
votes
1answer
28 views

WP_Query to display number of custom post type filtered (order by) taxonomy

I am trying to display the number of posts made in custom post type "incidents" by the custom taxonomy "store". eg. Store 1: 8 posts Store 2: 6 posts etc. I have been looking through here and ...
0
votes
0answers
13 views

AND relation in tax_query now working

I want to apply filters on 'retailers' custom post type. Filters are on the basis on following taxonomies. Shipping Type Release Type Raffles I am using AJAX to apply filters. (https://savior.d....
0
votes
1answer
24 views

Hide posts if user is added to it WP_query

I have this list of posts in wordpress. I've made a favorite function that when you mark something as favorite it gets added to the front of the line. The issue here is I run this 2 place. One top ...
0
votes
3answers
35 views

Getting posts by custom field value

I need to get posts with a price less than or equal to for example '1000'. The price is set in an arbitrary custom field. Trying to posts a price that is less than or equal to 1000 $posts = new ...
0
votes
0answers
13 views

Woocommerce sorting not working properly after adding 'woocommerce_product_query' hook and editing the post__not_in or post__in query parameters

So I have a code which filters my post depending on my custom field. This code filters my posts depending on user role, and which custom field is selected. I successfully managed to filter my post ...
1
vote
1answer
23 views

Display featured image from one CPT within another CPT query

I have a WP_Query for a CPT of 'fixtures' that has a relationship with another CPT of 'fixtures_teams'. I want to pull in the featured image from the relative team in fixtures_teams CPT. $query = new ...
0
votes
1answer
16 views

how to load the comment template from a plugin

I want to create custom design for the comments. comments_template() will load the default \comments.php. i have a file inside my plugin commentsnew.php how can i use this file for comments_template(...
0
votes
1answer
17 views

How to create better WP_Query to look for date time which is anywhere between two meta values?

The following arguments are used for WP_Query to check if a reservation for a game can be created. Meta input fields for post are created using ACF DateTime Picker and set to Y-m-d H:i:s $start_date =...
1
vote
1answer
20 views

Get Current User Id Inside a Loop Returns 0 For a Shortcode

I am having function, which has a loop for all the posts of given author. I use get_current_user_id() but that does not seem to work while inside a loop, or may be the shortcode troubles it. My ...
1
vote
0answers
29 views

WP Query related posts by tags

I want to display related posts ordered by multiple tags. So I need to create a function what will query posts with the most number of tags in common and display them in descending order. But also it ...
0
votes
1answer
25 views

get_query_var always returns the default value

I am really new to wordpress, and I am trying to build a page that updates the database with given arguments. For example, if the client application calls https://codonmaster.000webhostapp.com/ranking....
0
votes
0answers
18 views

Possible to order archive by selected post IDs, followed by regular order with WP_Query

I can run an SQL query like ORDER BY FIELD( id, 3, 2, 1, 4 ), title and return a list of posts starting with my ids 3,2,1,4 and the continuing with the rest of a query, bringing back all remaining ...
0
votes
1answer
15 views

Search for single post by 2 tags

i have "Tag1" and "Tag2" i want to find most recent post with both tags.So far i have tried this, i know im close, but it is listing all posts containing either tag. $args = array( 'relation' ...
0
votes
1answer
11 views

How can I get custom post types to recognize pretty permalink variables?

I'm using PODS to create a custom post type called "automobile" on my site. This results in a permalink structure that looks like this: /automobile/automobile-page I want to be able to send ...
0
votes
0answers
17 views

Order by meta_key field in Wordpress not meta_value field value

I have a requirement where I need to show all posts having thumbnail first and ordered by title and then remaining posts ordered by title Below is the code I tried $the_page = (get_query_var('paged'...
0
votes
0answers
55 views

Wordpress custom query sorted by date and a boolean WP_query

I have a custom post type 'specials' that has 2 meta fields 'expiration_date' and 'featured' Featured is just 1 or 0 and expiration date is a date picker field from ACF I need to write a WP_Query ...
0
votes
1answer
26 views

a WordPress connected to 2 database

Is it possible that Wordpress works from two databases? I would like the post published by web A to be reflected on web B Web A would only affect the information in the tables wp_postmeta wp_posts ...
0
votes
0answers
14 views

pagination on wordpress and not showing all results

I have this page that shows posts from a range of years selected of a form on a previous page. the first results display the 10 posts as set in args(post_by_page => 10); if there are more posts I ...
0
votes
0answers
15 views

Is there any way how to obtain / filter out product variations using WP query by title?

I was wondering if there was a way how to filter product variations by titles using WP query. For example if we wish to delete only certain product variations from all products that are accepted by ...
0
votes
1answer
29 views

How to pass multiple custom fields as shortcode's parameters

I'm learning how to pass parameters in shorcode, I know the basic step after read through WP Codex. But for now, I have plugin come with custom fields and as the title, I want to know how to do it. ...
1
vote
0answers
10 views

How to show optimized list of posts with all their attachment images

In page-images.php template I have created this code which displays a list of posts which belong to a category and order them by meta value. So basically it is like a category page, generally nothing ...
0
votes
0answers
27 views

WP_Query for custom taxonomies showing posts from non-specified terms?

I have two custom taxonomies "products" & "products-info" registered for custom post type "products-posts". There are three terms (shoes, shirts, pants) in "products". Similarly, there are two ...
0
votes
1answer
11 views

2 modal windows with ACF content on Archive page

I have an archive page that shows a custom post type with content entered in ACF. Inside each article, there are 2 buttons that open an Inquiry modal and a gallery modal. Now I have managed to get ...
0
votes
1answer
62 views

Display current post position in Elementor Posts widget

I'm using Elementor 2.6.8 + Elementor Pro 2.6.2 I'm designing an Archive template to display a list of Custom Post Types filtered by custom taxonomy terms. I'm using Posts Widget from Elementor Pro ...
1
vote
1answer
17 views

list pages using page.php and NOT page-{slug}.php

I made a view templates for specific slugs page1-220 use page.php contact uses page-contact.php service uses page-service.php Now I want to list the pages with their templates on a "overview" ...
0
votes
0answers
12 views

Paged WP_Query is quitting on page 3

I am having this problem where every time I run this, it stops on page 3. There are about 15000 products that are published. So there should be at least 30 pages. I narrowed it down to the $loop = ...
0
votes
1answer
55 views

Set default option in dropdown of WP_Query?

Edit: I have an archive page for a Custom Post Type. Each article that appears on this page has information entered via Advanced Custom Fields about that article, and a button that opens a modal ...
0
votes
1answer
22 views

Appending to existing WP_Query's meta_query if exists

I'm looking to hook into pre_get_posts to alter WP_Query and put in a condition for the meta_query portion. I want my hook to be non-destructive to any other hook that may have modified this key. ...
0
votes
0answers
24 views

Get records for specific taxonomy only

Currently this code is displaying all records for all taxonomies but I only want to display the records for the specific taxonomy that the user clicks into, so I think I need to filter by slug or get ...
0
votes
1answer
46 views

How can I group posts by months and years?

I have posts under a custom post type which I like to display in a page grouped by Year and Month. In the page template that I create, I managed to separate them by month, but still without grouping ...
0
votes
2answers
46 views

How to add posts, manually, to a wp_query?

$recent_query = new WP_Query(array ( 'post_status' => 'publish', 'posts_per_page' => -1 ) ); //$recent_query->posts[] = get_post(1480); //$recent_query->posts[] = get_post(1443);...
0
votes
1answer
22 views

How to display particular set of wordpress post on a webpage?

I have a wordpress/php code as shown below which display list of posts on a webpage. Php code: $special_reports = new \WP_Query([ 'post_type' => 'cpac-special-report', 'orderby' => '...
3
votes
2answers
85 views

Does tax_query really beats meta_query in all situations?

Let me start saying that I know a 'tax_query' is faster than 'meta_query'. It's always recommended to use taxonomies over custom meta when filtering by custom data is required, but here I found ...
1
vote
1answer
14 views

tax_query returning all posts instead of selective posts in WP_Query

What I am trying to do Hi, in my site I have a custom post type called projects, then I have created a custom taxonomy for my projects post type called project_catagories. Now in my projects archive ...