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
1answer
16 views

How to not display tags with less than X posts

Is there a way to avoid displaying tags which have less than X Posts? the answer here is close Remove from Google Tags with less than 2 posts however it suggests to send a respose header to google. I ...
0
votes
1answer
19 views

Getting rid of unwanted nonSQL syntax characters when debugging a query

I am trying to debug a SQL query, but I am getting a lot of @r and other unwanted characters right before I run the query like so: print_r($query); die; $rows = $wpdb->get_results($query); I get: ...
0
votes
0answers
10 views

How to add a "base" filter for all posts visible to visitors on the site?

I'd like to filter all posts ever visible to my visitors by the posts' custom meta (box) tag value. I added a post meta box "access_required" and I want to check if the post's ...
0
votes
0answers
11 views

Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?

I am using the following query to get past and upcoming events: $post_grid_args['meta_query'] = array( 'relation' => 'OR', // Get upcoming events array( 'key' => 'date', ...
0
votes
0answers
10 views

Sending simple variable on single page to WP JSON

I like to send specific data from a post to my JSON response in Wordpress. I like to send the output of the variable "hatus" to the JSON response, but it does not seem to work. <?php ...
0
votes
1answer
35 views

get_posts query is taking about 40 seconds to execute

I have a meta query in get_posts that's taking a ridiculously long time to complete. It works fine, but it just takes way too long. I have a custom post type named event. On every event post, there is ...
0
votes
0answers
9 views

create a custom query for posts managed by Restrict Content Pro

I'm using the popular membership plugin Restrict Content Pro. I'd like to create loops that query for posts that are being marked as being restricted by RCP. How can I do this?
0
votes
1answer
13 views

Is this meta query problematic?

I have couple of checkboxes determine the range of min and max people capacity for events. For example: 0 to 100, 100 to 200, and so on. I need to filter them through with a meta query but currently ...
0
votes
0answers
16 views

Sort custom post by custom field if none order by latest release

I basically want my post order first on upcoming releases and if there are non or no more I want to order them by latest releases. I would also like the upcoming book releases to be ordered by nearest ...
1
vote
0answers
74 views

wp_query ignoring custom post_status

I have a custom post status called 'dead.' I am trying to create a wp_query to show all posts for a custom taxonomy. If I specify 'any' for the post_status I do get published posts and my 'dead' ...
0
votes
2answers
18 views

Get posts that do not have the same tags as current

I'm trying to get all posts in a custom plugin loop that DO NOT share the same tag as the current one. I'm trying: $events = tribe_get_events([ 'start_date' => 'now', 'eventDisplay' =&...
0
votes
0answers
25 views

How to combine meta_query and date_query with condition in Wordpress

I have a problem with the combination of meta_query and date_query. I have meta_data with key is start_time. I want to query with the condition: if start_time is not empty then use with condition '...
0
votes
1answer
19 views

the_posts_pagination() not working in wpquery

I'm trying to create pagination to the custom wp_query here is my code: <?php $btpgid=get_queried_object_id(); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = ...
0
votes
1answer
23 views

Which meta_query and post_content blend is better in WP_Query, performance wise?

I need to WP_Query for posts which: either have a postmeta 'answer' set to 'yes', and whatever post_content; or have 'answer' set to 'no' but only if post_content is empty. So in an ideal world ...
0
votes
0answers
7 views

Customize the Sorting Dropdown in WooCommerce use another list or more page

it would be great if there was a way to change the default sort by dropdown in WooCommerce on the shop page. but I want to use list page or other page for default sort by dropdown in wp-query.
0
votes
1answer
29 views

Pagination of custom page with custom fields query

Hello I have created a custom php file that I use to show specific posts by value inside the a custom field. So for example I have 100 posts, let's say they all have custom field MyTitle and 10 of ...
0
votes
0answers
28 views

How to Join wp_posts & wp_postmeta table using custom query

I am trying to create pagination for product details with the help of wp_posts & wp_postmeta table for my woocommerce custom code for admin area. There are 85 products in shop & i want to ...
0
votes
1answer
23 views

How to group only VISIBLE posts? [closed]

Good afternoon With the help of a fellow user here I am finally able to display all posts on a single page with the respective post month as a divider between the groups. So it looks something like ...
0
votes
2answers
35 views

Is it safe to access the underlying mysqli object from \wpdb for custom queries?

I am writing a custom (bespoke, for 1 client, not for publication and general consumption) plugin, that needs to access custom tables. In general with WP,I follow the principle of using the higher ...
0
votes
1answer
17 views

Group first, 2nd, 3rd, etc posts by category terms

This is a weird one, and maybe impossible. I have a design where each category has a certain style in the index. Everything is in a grid so that one category takes up two columns, another takes up two ...
0
votes
1answer
25 views

How to display all posts divided/ordered by post date? [closed]

Good afternoon My task is to display all posts on a page, with the respective post month as a separator. So something like this: January 2021 ----------------- post 1 post 2 February 2021 ----------...
0
votes
0answers
28 views

Alike Shortcode using in Custom Shortcode

I'm using Alike plugin to compare my custom post types, Alike provides shortcode [alike_link] to run the procedure and I have created a shortcode to display my custom post type. In this shortcode I ...
0
votes
1answer
28 views

Sort custom posts by date and then by taxonomy

i am having this issues for month and i can't figure out how to solve this one: I am working on a website, where you can check out cultural events in my region. This is just to let you know of what i'...
0
votes
0answers
21 views

How to merge multiple foreach into 1 foreach and sort by date

How to combine multiple foreach in only 1 foreach and than sort the foreach based on date? I am having a WP query based on a custom post type I created called mm_agenda. I know I can create 2 arrays (...
2
votes
2answers
64 views

How to display the number of articles published per user

How to display the number of articles published per user excluding users who do not publish articles. My message type is recipe. I would like to receive a code to get there in wp-query thank you very ...
0
votes
0answers
35 views

WP query meta key is returning an array, how can I compare this to a date? [closed]

I'm using the ACF Multi Dates Field plugin with ACF to allow user to select multiple dates for an event. I need to compare the return value of the multi date plugin to the current days date. But the ...
0
votes
0answers
34 views

How to wp_query every Sunday between a startdate and enddate?

I'm trying to output all Sundays between 2 different dates (startdate and enddate). The following PHP code made this work pefectly. But how to get these dates by the WP_Query? PHP example (works): $...
0
votes
2answers
47 views

What's wrong with this meta query? (order by meta key, then title, doesn't work)

Here's my meta query: $taxonomy_term = 1494; $args['meta_query'] = array( 'relation' => 'OR', 'mp_exists' => array( 'key' => 'tdlrm_mp_'.$taxonomy_term, ...
0
votes
0answers
64 views

Order (by ASC) posts with meta_key so posts without values are last

I am trying to figure out sorting posts with prices in one meta query, so the posts without prices are shown last, when ordered by ASC and not first. Right now I am temporarily not showing posts ...
0
votes
0answers
20 views

How can I modify the query by adding to the existing query?

I have two functions that both modify the query, however the most recent one I've created, I would like to add this modification alongside the previous one (i.e. not overwriting it). The idea is that ...
0
votes
0answers
36 views

WP_Query custom post with by general tags

I'm trying to query custom post type of products and all the tags inside the $terms variable. I want this to work whether there is a single tag or multiple tags. The tags are not unique to the ...
0
votes
1answer
12 views

array of meta values using WP_User_Query

I don't see that it is possible when I look at the WordPress documentation but I wanted to confirm. I want to check multiple meta values against one meta key eg: $user_query = new WP_User_Query( array(...
0
votes
1answer
36 views

unable to use 'new WP_Query' in AJAX call

I'm trying to create category filter for posts. I usually work with get_posts function but this time I need to keep pagination, that's why I'm trying to use new WP_Query. I have successfully created ...
0
votes
0answers
7 views

How to exclude meta no index pages from wp_list_pages

Can I exclude pages that use a meta no index or are no indexed from a plugin like Rank Math from wp_list_pages args?
0
votes
0answers
22 views

WP Query: If field X is empty, show posts based on field Y

Sorry for the bad title, had difficulties phrasing this questioon in a TLDR fashion. I have a custom post type for events on my website. Some events only happen in one day, whilst other events might ...
0
votes
0answers
37 views

Query custom post type that has a serialized relational advanced custom field value

I have a custom post type "issues". I am using Advanced Custom Fields to add a relational field called "articles_from_this_issue" where the admin can select multiple articles. I ...
1
vote
1answer
21 views

Wordpress search posts by author name with autocomplete

I am using autocomplete code as follows: functions.php // add the ajax fetch js add_action( 'wp_footer', 'ajax_fetch' ); function ajax_fetch() { ?> <script type="text/javascript"> ...
0
votes
1answer
40 views

Using a new WP_Query inside the loop

I'm trying to query the database to count log entries for file downloads, this is then displayed an the thumbnail when listing search results. From Search.php ` <?php //JAYJAY Get the download ...
0
votes
1answer
27 views

Why are my wp_query args being ignored if post_type = CPT

I have a few different CPTs setup; 'jobs', 'events', 'products'. They are being displayed on various pages of the site, in sidebar or footer areas. Using the following code, my CPT gets output, but ...
0
votes
1answer
17 views

Error in pdf generating plugin using FPDF

I'm trying to create a plugin using FPDF to create an options page to print custom post types. Here is my code: <?php /* * Plugin Name: RT FPDF Tutorial * Description: A plugin created to ...
0
votes
1answer
42 views

Exclude a specific post in a Custom Post Type

I have a very simple query to display all my posts in a custom post type: <?php $page = get_page_by_title('Duck'); $args = array( 'post_type' => 'sessions', 'post__not_in'...
0
votes
1answer
51 views

Adding a tax_query to a WP_Query Object

Is it possible to modify a WP_Query object to add a tax_query? That is -- I'm able to add a tax_query when instantiating a WP_Query object $q = new WP_Query(array( 'post_type' => 'post', '...
0
votes
0answers
20 views

Wordpress rewrite with custom parameter doesn't work

I'm currently developing a plugin which takes a parameter from URL (example: example.com/product_id/1234 is converted to example.com) and passes it in WP_Query (supposedly this should be used instead ...
0
votes
0answers
16 views

Manipulated offset and pagination, can't display last post anymore

As you can see from the code below, i'd like to show the last post with a design and the other posts with a different design on the first page. For the rest of the archive pages the last post won't be ...
0
votes
1answer
12 views

Query pages created by deleted users

I need to query all and any pages that are created by either deleted users or users that are no longer users of the website. Here is my query $args = array( 'author' => '0', 'post_type' => '...
0
votes
0answers
9 views

have to do a while have post to show for two custom post types sharing the same taxonomy?

So I have 2 custom post types. One is a Location that has a hierarchical taxonomy called state. So basically one location page being Salt Lake City which belongs to the Utah state Taxonomy. The other ...
0
votes
0answers
30 views

Using Ajax and WP_Query to load more posts on category page fails

I'm using the code below to load more articles on click beneath the 10 posts that are already loaded on page load. It works perfectly on my front page, but when I use it on my category page, it will ...
0
votes
0answers
19 views

Add metabox if there is at least one post available

So I am building a WordPress Dashboard widget which will showcase all posts & pages where a Gutenberg Block is active. The below code does it's job and pulls in an array based on get_posts(). Here ...
0
votes
1answer
26 views

How to use custom page for all posts with custom url, call another directory?

I have tried many different codes: <a href="<?php echo get_template_part( 'template/test/post' ); ?>"> Test 1</a> <a href="<?php echo ...
0
votes
0answers
11 views

Dynamically load Woo Products in Block for landing page via Querry String Param

First time posting here. I am trying to load woo commerce products based up a query string param for a content block on a landing page. I only need this for two variables "Product Category" ...

1
2 3 4 5
109