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.
5,738
questions
0
votes
1
answer
206
views
How to add $args to any running wp_query from function.php?
Is it possible to add WP_Query arguments from functions.php to any of wp_query running on current page? For example, I want to add $args['order'] to current running wp_query on any pages.
0
votes
2
answers
62
views
How do I check if an article is popular this week?
I use this function to set and get post view of post in my WordPress
function wpb_set_post_views($postID) {
$count_key = 'wpb_post_views_count';
$count = get_post_meta($postID, $count_key, ...
0
votes
1
answer
499
views
Merge 2 custom post type posts and taxonomy terms and sort ascending
We have a most recent block where we query a taxonomy for a custom post type and posts from two custom post types. This we do using this code
Full Code
<?php
/**
* Highlights block
*
**/
// ...
0
votes
1
answer
164
views
Single field to search for matches on post ID or meta values
I'm sure someone else had this need somewhere... I just couldn't find it!
So I have a search field where I want to write something and what I write returns me WooCommerce orders.
This is my working ...
0
votes
1
answer
340
views
Tax Query only returns for the first of several terms
I'm trying to query a customer post type where the results may be within one of several associated terms. The issue however is that only the first term yellow-gold-jewellery is being returned for, and ...
0
votes
1
answer
188
views
Combine 2 arrays in a query parameter
I'm trying to exclude upsells using post__not_in but I already have a value and do not know how to combine the two.
I tried this:
'post__not_in' => get_upsell_ids(), [get_the_ID()]
But it is not ...
0
votes
1
answer
286
views
Pagination on template page for custom query redirecting to index.php
I'm building my first theme and have a template page "page-blog" with a custom wp_query. I've tried adding pagination to the query but so far the pagination redirects to the index page. As ...
0
votes
1
answer
104
views
Add ACF field in a query
I am trying to set category_name of a query using an ACF text field but I am getting all posts instead the post of the category I want.
$category1 = the_field('category1');
$args1=...
0
votes
1
answer
205
views
Getting blog pagination to work on page set as front page
From what I understand, if the page is the front page (using front-page.php) you would use get_query_var('page') and for other pages you would use get_query_var('paged'). I have a condition for this ...
0
votes
1
answer
26
views
Set front_page programatically after user login via query, while leaving site option alone
I want to change the front page based on who is logged in.
If User_Bob is logged in, the front page is "Bob" [post id: 123]. If User_Jane is logged in the front page is "Jane"[post ...
0
votes
1
answer
391
views
how to get this tax_query working?
I have wp_query including custom taxonomy terms which works if all the fields have values. Otherwise, it is giving 0 results.
This is the form that is used to get the taxonomy terms.
Based on the ...
0
votes
1
answer
837
views
Select2 AJAX and WP Query Returns ALL and does not filter
So I'm a bit stumped here. I regularly use Select2/AJAX/WP_Query to search for and retrieve default WP post-types and my own custom post-types. Almost every site I've built over the past few years ...
0
votes
1
answer
134
views
Can't fetch Custom Post Type Data through Custom Query
I have a custom taxonomy "Shade Type" which contains two types
Ready Mix
DCM
I am querying the DCM value to display in WooCommerce tab. My code is fine but I am not getting any values in ...
0
votes
1
answer
30
views
how to get Nearby zipcode
I need to get close/Nearby to zipcode list data zipcode so I'm using the example table name li_zipcode:
id
zip_code
latitude
longitude
1
35004
33.557327
-86.534508
2
35005
33.604744
-87.042442
3
...
0
votes
1
answer
45
views
Loop increase in while loop not working
I'm aiming to create a layout where the first post is full-width in the loop, all the posts after are 50%.
I created this code:
<?php if ( $query->have_posts() ) : ?>
...
0
votes
1
answer
889
views
get_the_ID() in the footer returns wrong value
I'm using get_the_ID() in footer.php but it returns a wrong value.
It might come from any of the plugin which is altering The Loop without resetting it after with wp_reset_postdata() as mentioned in $...
0
votes
1
answer
39
views
Wp-query Order By problem
I'm trying to sort a query according to the order they write it in but it takes an order by ID.
The variable $idpaginas prints: 20659,20626,20585,20616,18464,19748,19991,18520,20588,21268,18753,20556,...
0
votes
1
answer
24
views
Create a loop on my pages with new "WP_Query"
I wanted to loop through these four pages. Basically I would like my loop create a "li" by "page_id". I just know this is from my "new WP_Query" which is not good.
How ...
0
votes
4
answers
80
views
Trouble inputting variable into WP query
Not sure the best way to describe this, but basically I am defining a variable ($cat) which chooses a taxonomy based on a number defined just before the query is called, but as the number is defined ...
0
votes
1
answer
2k
views
WP_Query orderby not work with meta_key
I want to order the post by 'leasenum' in my archive-shop.php.
I want to filter the specific 'mall' .
The result set is correct but the order is wrong.
The orderby only works if I remove the 'meta_key'...
0
votes
1
answer
91
views
Get All posts by Tag_Id not working, query seems to contain extra term_taxonomy_id
I have the following simple query
$args = array('posts_per_page' => 7,
'tag_id' => 43,
'post_status' => 'publish',
);
$q = new WP_Query($args);
echo ($q->request); // ...
0
votes
1
answer
22
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
1
answer
50
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
1
answer
110
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
1
answer
3k
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
1
answer
319
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
1
answer
39
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
1
answer
426
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
1
answer
718
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
1
answer
231
views
queried_object using pre_get_posts gets notices and warning
My code is getting me the result I want on my page, I'm fetching another post and my theme is outputting all of the relevant data I need on the page as expected.
function replaceQuery( $query ) {
...
0
votes
1
answer
1k
views
WP_Query object: what's the difference between [query] and [query_vars]?
I'm debugging a query created by the Post widget of Elementor, it should exclude the post with id 12419. I see the
[post__not_in] => Array
(
[0] => ...
0
votes
1
answer
20
views
Having Issue on Ordering CPT by Custom Field In Custom WP Query
Having a Custom Post Type loop like this, I am able to return the result on page BUT I am not able to set Order By of display using my own Custom Field.
As you can see here
$topic_number = ...
0
votes
1
answer
220
views
Should $query-> be used with conditional tags?
The function below limits the search results to posts only.
function exclude_pages_from_search_results( $query ) {
if ( $query->is_main_query() && $query->is_search() ) {
$...
0
votes
1
answer
45
views
post_parent don't work and return 0 page
I'm trying to resume pages on WordPress that have a specific page as the parent page.
Why is this not working? This is my args code for loop:
$args=array(
'post_status' => 'publish',
'...
0
votes
1
answer
322
views
Query all post and CPT from 2 specific taxonomies AND by ACF custom field
I need to build a complex query.
I want to display all posts, and 2 different CPT posts in specific taxonomies. All of these posts need to have been checked to be displayed. The checkbox is added with ...
0
votes
1
answer
399
views
I need help using pre_get_comments to limit comments in the comments admin screen
I am trying to limit the comments in the comments admin screen to:
Display all comments for the current user
Display all the comments made on the current user's post
if(!current_user_can('...
0
votes
1
answer
42
views
Is WP Query skipping to check next post when an argument is not met?
If a post fails to meet the first argument (publish), does wp query still do the meta comparison or is it skipping to check the next post immediately?
The question is NOT about the output, but rather ...
0
votes
2
answers
369
views
How to check in functions.php if there is data in a WP_Query?
I have 2 different WP Query on the home page.
I need to check $home_query condition in functions.php then I want to do something if $home_query returns null.
I tried with pre_get_posts action I couldn'...
0
votes
1
answer
120
views
WP Query causing timeout
Im trying to show taxonomy names along with their counts for a donut-chart. This is what im doing;
<ul class="pie-chart__legend" id="donut1">
<?php
$wcatTerms1 = get_terms(...
0
votes
1
answer
759
views
Utilising an existing page while using the "s" query parameter
I'm trying to load/utilise an existing page template (templates/results.php) while making use of the "s" (search) query parameter. For example: example.com/results?s=lorem
Currently, this ...
0
votes
1
answer
206
views
Shortcode with 'year' parameter
I would like to display posts with a 'year' parameter. For example: to display posts from 2020, the shortcode should look like [archived-posts year="2020"]. I have tried my code below but it'...
0
votes
1
answer
625
views
WooCommerce sort by SKU
So, I've tried https://gist.github.com/bekarice/1883b7e678ec89cc8f4d on my website. It works good, as long as all the products have SKU. If a product doesn't have SKU, it's not displayed at all.
This ...
0
votes
1
answer
621
views
Get user posts with custom WP_Query on author.php
I try to show custom post list with WP_Query on author.php like this:
<?php $args = array( 'post_type' => 'post', 'author' => 'get_queried_object_id()', 'posts_per_page' => 9 );
$...
0
votes
1
answer
493
views
search blog posts by author first name and or last name
I am trying to create and endpoint where blog posts can be searched by author first name and/or last name. I was trying to do this with WP_Query but it uses the user nice name for the search which is ...
0
votes
1
answer
409
views
date_query in pre_get_posts out of memory
I'm trying to apply a Datefilter for specific categories.
Wordpress crashs with a out of memory error. Is this a server problem or is my query wrong?
At first I tried query -> (...) but with ...
0
votes
1
answer
210
views
posts archive page - closing WP_Query loop correctly [closed]
I am trying to use an example of the loop shown in this post Output yearly archive within a page
to output post links grouped by year
page-archive.php
<?php
/**
* Template for displaying archive ...
0
votes
1
answer
2k
views
Pagination not working on custom query on a page
I have a custom query on a page (it is not an archive page), it works just fine, but I want pagination and it is not working at all...
<?php
$paged = (get_query_var('...
0
votes
1
answer
551
views
How I can change the condition or compare operator for WP_Query in pre_get_posts
So here is my problem
I want to show Posts if have same category if not have post then show post of same tag. And to do that I am using "pre_get_posts" action. and setting query like ...
0
votes
2
answers
450
views
Query within a foreach within a query (queryception)
I'm achieving this list in a really roundabout way at the moment and I feel like I should be able to do it with a foreach instead of separate queries for each "House" (House is a CPT and is ...
0
votes
1
answer
714
views
WP Query Meta Value - How To Identify Specific, Unique Values?
On my Club Profile pages, I'm displaying a list of posts (Player Profiles) where the title of the specific Club Profile page is also a meta value contained in those Player Profiles against one or two ...