Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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 given request.

0
votes
0answers
18 views

Help me to give a PHP Snippets

I wanna give points to members of my website when they rate our listings/products/posts, depending on 1star, 2star and so on they will get 10points, 20points...ultimately 5star get 50points. I'm using ...
0
votes
0answers
15 views

WordPress | WP_Query | The post 'offset' is not working and posts_per_page is not set to -1 [duplicate]

Why is my random post query ignoring the offset value? <!-- RECENT BLOG POSTS --> <?php $recentargs = array( 'post_type' => 'post', 'post_status' => 'publish', '...
0
votes
1answer
10 views

Multiple pagename WP Query

I wonder if I can use WP_Query() with multiple slug like p => array(1,2,3) I have tried using pagename => array('accommodation','activities','restaurant') but pagename expects a string and ...
0
votes
2answers
27 views

Best choice for multiple loop in page?

My home page include five loop. currently i use wp_query but is it optimized ? best choice with get_posts ? my code looks like that // First loop $args_dogs = array( 'post_type' => ...
0
votes
1answer
18 views

I want to place a post before all others from an ACF boleen field

I am currently trying to retrieve an post (to put it before all others in the search results of a search filter I created) from an ACF boolean field (and I am a beginner), so I made this script but I ...
0
votes
0answers
25 views

WordPress Comments sort by custom meta key

I want to sort comments by a number of likes which is saved as a meta_key in the wp_commentmeta table: I have tried two ways but it doesn't sort the comments by most liked comment at the top. Please ...
0
votes
0answers
8 views

wp-query: order by a custom-field and get one random item of another custom-field

I have a "brand" page (ex. Nike). When I click on "Nike" page I would like to show a list of all categories of their products (ex. shoes, thirts ecc). Each category of their products is listed by a ...
4
votes
2answers
57 views

How to know if get_posts() failed?

So I see that get_posts() function return an array of posts. If there are posts, it returns an array of posts. If there are no posts it returns an empty array(). If there are posts, but the querying ...
0
votes
2answers
39 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
1answer
26 views

WP Query Conditionally query meta and taxonomy

I develop a plugin which includes a custom post type that is displayed as a list within WP Admin. There are varying levels of users defined within the plugin and a few other options which determine ...
0
votes
1answer
24 views

Debugging wp_query orderby for taxonomy

I cannot seem to find where WP_Query adds the orderby clause to a SQL query. I am using this code: function wpd_team_taxonomy_queries( $query ) { if ( !is_admin() && $query->is_tax( 'team'...
0
votes
1answer
32 views

wp_query with ajax

I am trying to filter posts by year using WP_QUERY with AJAX And the current builder i am using is DIVI(for front end). Result Everything loads fine and i am facing one final roadblock that is when ...
0
votes
1answer
14 views

Restrict content based on user registration date

I’m looking for a way to restrict content displayed to subscribers based on when they registered. Basically, every week new content will be posted and I want to be able to restrict subscribers from ...
0
votes
1answer
23 views

Custom taxonomy.php not working

I have created a custom taxonomy called "series" (code below) and two pages: taxonomy.php and a taxonomy-series.php 1)I noticed that siteurl.com/series does not work I get my 404 page, but if I were ...
0
votes
0answers
23 views

Custom Post Type - Display all, wrap in groups of 3

I've got a custom post type for staff members in a project I'm working on. I want to display all staff members in a slider, with groups of 3 rotating. I need my listing to end up looking like this, ...
0
votes
1answer
34 views

How to pass query string vars between admin pages?

I want to pass two query string variables, and their values, from one admin page to another. When I try to do so, on the final destination page, it indicates the variables are not set. My code is ...
2
votes
2answers
112 views

RSS feed with specific keyword

I am able to get articles as RSS feed from below url http://wordpress_site/blog/feed I am also able to get articles from BlogSpot with specific keywords as below https://www.yourblogname.blogspot....
0
votes
2answers
29 views

Hiding load more button with wp ajax

im using ajax to load more posts for custom post type using WP QUERY, now i'm having trouble hiding button if it's last post or if there are no posts left ( behaviour im getting is when i click it ...
0
votes
1answer
40 views

How to query for custom field within Gutenberg block from outside of that post?

I created a custom field inside of a custom Gutenberg block (using ACF). It is a Post Object field that accepts multiple post IDs. When inside that post, I can pull the data just fine and everything ...
0
votes
1answer
22 views

Make pagination work as a carousel (custom query)

I'm using a custom query on my static front page in order to show my posts, but I would like my pagination to work kinda like a carousel (instead of loading an entire new url). So, basically I want ...
0
votes
1answer
37 views

Display Search Results by tag_ID in my search.php

I have my search.php working fine. But I'd like to display the search results in my search.php filtered by tag_ID when is coming from another search form. I've tried several things like: wp_parse_str, ...
0
votes
0answers
10 views

update_post_meta performance in a loop woocommerce

I have a simple question, I am working on the list order screen of woocommerce and want to add some buttons that via ajax will update some data to the database using update_post_meta. The issue is ...
0
votes
0answers
13 views

Change the “page” slug in pagination [closed]

Above code has not helped me and i am still not able to solve my problem please help me How to replace "page" from "#" in default url of pagination of wordpress as my current url is /page/2
0
votes
2answers
22 views

Query posts by Post title

I use the following ACF query to generate a list, works perfectly. Now, however, I want to order my list by standard WP “post title” instead of ACF custom field “datum” How can I do that ? // args $...
0
votes
0answers
11 views

Query Order By Number Variable From API

Trying to order the query by a number variable $total that is a storing an api containing a number. My goal is to output an ordered list with the number ($total) sorting the list. I've looked around ...
0
votes
2answers
19 views

How to query most recent post for each author?

Can anyone provide a sample MySQL or WP_Query code snippet that returns the most recent post for each author on a single WordPress site? For example, if the site has 10 authors but 500 posts, then the ...
0
votes
1answer
36 views

Wp includes access control

Everyone peoples can easily acess to my wp-includes how can i hide or not visible files to users can anybody help me regarding it this is my wordpress website link see everybody can see this https://...
1
vote
1answer
31 views

Create A Loop With A Variable Number of Posts For Each Bootstrap Row?

I'm attempting to create a single WP loop, using a custom query, to display a custom-post-type - using Bootstrap 4 markup. The complicating part for me is, I'd like the number of posts for each row ...
2
votes
1answer
21 views

Group posts by custom field

I am trying to display a list of all child pages using wp_query and so far I have created a function that retrieves all the child pages for the current page, however I need to sort these pages into 2 ...
0
votes
1answer
20 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 ...
0
votes
1answer
12 views

Display posts side by side with custom query

I'm trying to organize my posts side by side but they keep being displayed vertically. This is my code: <div class="row agenda-box justify-content-start padding minheight-40"> <div ...
0
votes
1answer
30 views

How to count posts with specific arguments

I'm wondering how I can request the amount of posts by passing certain arguments (you could see this as part of a "query"). See the example below. $args = [ "numberposts" => -1, "...
0
votes
0answers
16 views

pre_get_posts meta_query for dates interval

I have an "activity" custom post type, that has start and end dates introduced via custom fields. I want to add a meta_query argument through pre_get_posts, to get "activity" posts between two dates. ...
1
vote
1answer
20 views

Function to check if author has posted within the last x days

Is is possible to check whether an author has posted in the last X days? I am currently using this function to determine whether he has posted at all. $args = array( 'post_type' => '...
0
votes
1answer
19 views

How much does $wpdb->prepare(), then $wpdb->query() VS straight $wpdb->query(), can slow down the load time of whole page

Let's assume that the $wpdb->query() is properly escaped as needed, so there is no must for use of $wpdb->prepare(). However, some new requirements at Envato, not the w.org, requires to go over ...
0
votes
1answer
13 views

Sorting query_posts() with a complex orderby filter

I'm trying to order my posts with a complex orderby scenario which uses the CASE and WHEN syntax. To achieve that, I've created a filter : add_filter( 'posts_orderby', 'order_properties_by_reference',...
0
votes
1answer
25 views

Using a variable within the blog posts array query - posts_per_page as variable

I am trying to use a variable that my content person can change when editing pages to display a different number of blog posts. Here I have declared the variable: <?php while( have_rows('...
0
votes
0answers
13 views

How to order WP_Query by parent for hierarchical Custom Post Type?

How can I get all items under specific parent and order them by menu order in hierarchical Custom Post Type? Lets say I have this posts structure: Fruits Apples Bananas Plum Cherry Vegetables ...
0
votes
2answers
15 views

Is there a way to control both Order By and Order query parameters from one input field

I want to give the user the ability to order posts by post date/alphabetically either on ASC or DESC order through a select input on an archive page. The easy way would be to show two inputs on the ...
0
votes
1answer
30 views

Custom Query Pagination not working on static front page

I'm trying to add pagination to my site but it isn't working. Here's the code: <div id="gridcontainer" class="carousel"> <?php $currentPage = get_query_var('page'); $counter = ...
1
vote
2answers
42 views

need to exclude APP_TAX_STORE => $term->slug

I have this code: query_posts( array( 'post_type' => APP_POST_TYPE, 'post_status' => 'publish', 'posts_per_page' => 4, ...
0
votes
2answers
21 views

query_posts problem - need help

I have a taxonomy called coupon_category. In a query_post I am trying to call all posts from related custom taxonomy with the same coupon_category. If I use: <?php // show ...
0
votes
3answers
36 views

Post Template Query with WP_Query?

I've seen this solution for querying pages based off of template type: Page template query with WP_Query I'm having trouble getting it to work with posts, that are using a "Single Post Template:" ...
0
votes
0answers
19 views

Using a meta_value or postdate to to query and orderby

How do I structure a sql that: 2 checks if meta_value is in future or has no meta_value at all and 1 orders by meta_value (meta_key => datum_event), and conditionally if this meta_value is empty ...
1
vote
1answer
7 views

Random order of WP_Query results with highest meta value

I need to random of cars with highest price. My code: $argsLoop = array( 'post_type' => 'cars', 'posts_per_page' => 12, 'paged' => 1, 'meta_key' => '...
0
votes
1answer
30 views

Exclude posts in home slider from sections

I have home page with a main slider and news section. Main slider Sport section news Economy section news Politic section news and others section The main slider get posts by tag ='slider', and ...
0
votes
1answer
19 views

WP_Query for showing specific post by id

but it just shows the first post, I need to show three posts, please help me $the_query = new WP_Query(array( 'p' => '272 282 292',)); if ( $the_query->have_posts() ) : while ( $the_query-&...
0
votes
1answer
23 views

Query post with meta_query where date is not in future

In my args I would like to exclude posts where the datum_event is not in the future. Currently it only displays posts with datum_event values that are in the past, but because older posts don't have ...
0
votes
0answers
12 views

How to get_comments() ordered by date and parent?

So my starting point is: <?php $comments = get_comments(array( 'post_id' => $post->ID, 'status' => 'approve', 'type'=>'comment', '...
3
votes
1answer
16 views

Get array of posts from the current archive page loop

Classic WordPress loop (for example in archive.php) looks like this: if ( have_posts() ) : while ( have_posts() ) : the_post(); get_template_part( 'template-parts/content', ...