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
0answers
14 views

Single WP Query that Displays Category Name and Posts in that Category

I am trying to create a WP Query that I will put into a shortcode to be displayed on a page. I only want the newest 5 posts to show up for each category. Additionally, for performance, I want to ...
0
votes
0answers
9 views

Sort wp_query by variable created inside the loop

I have a custom loop that pulls all the child pages of the current page, and displays them. However, I need to order this query by the $first_row_image variable that is created inside the loop. This ...
0
votes
1answer
14 views

get_posts() not working with multiple statuses

I am running the following code: $posts = get_posts([ 'post_type' => ['my-type', 'another-type'], 'numberposts' => -1, 'order' => 'ASC', 'orderby' => 'title', ...
1
vote
1answer
62 views

Custom query for sidebar isn't returning results

I'm trying to create a shortcode that runs a custom query based on Yoast's primary category meta key. The goal is to pull posts with the same meta key value of the post being displayed and show 4 ...
0
votes
0answers
18 views

How to query to return custom post types with categories and custom taxonomy?

The following query is in a function used to filter posts based on user selection on the front-end. This site has blog feeds(CPT) by different authors that users can select to show by choosing any ...
2
votes
1answer
58 views

Search product by brand name in wp_query

I use this to search product by name on 2 categories: <ul class="products"> <?php $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( '...
0
votes
0answers
24 views

How to add new array to existing meta value array?

Header code $user_id = get_current_user_id(); $existing_setup = ( get_user_meta( $user_id, 'setup', true ) ) ? get_user_meta( $user_id, 'setup', true ) : ''; bottom code if ( ! function_exists( '...
0
votes
0answers
15 views

get_the_author_meta('ID') not working in wp_Query author.php

i use this code to show the latest news published by the author in author.php. But it doesn't work properly, and each author's page only shows the latest posts in this post type. <?php $...
0
votes
0answers
11 views

how display related posts first by tags then by categories?

this is my code $q = new WP_Query( array( 'posts_per_page'=>3, 'tag__in'=>$post_tags, 'category__in'=>$post_categories, 'post__not_in'=>array(get_the_id()) ) ); i want display related ...
-2
votes
2answers
29 views

have_posts order by title descending

I have custom post type 'movies' listing which i want to order by title, descending. Currently it sorts by post id. The code is: <?php if( $movies->have_posts() ) : ...
0
votes
0answers
25 views

Create foreach for meta_query to ACF checkbox

This is my wp query: $arg = array( 'posts_per_page' => -1, 'post_type' => 'elanlar', 'tax_query' => array( '...
0
votes
0answers
24 views

WP_Query - How To Query Only Custom Posts With No Children of Their Own?

I have an (apparently) unique problem I've been unable to find an answer to anywhere, or my head has simply become stewed. Using WP_Query to only show child posts is easy enough, or to display only ...
0
votes
0answers
18 views

how to create a shortcode from a variable in plugin

im using WP User Frontend Pro plugin i want to echo the pack title using a shortcode to put it in bakery visual all what i know is this is the title $pack->post_title; i tried something like this ...
2
votes
1answer
156 views

Use WP_Query with a custom SQL query

To fetch the posts I have a query which includes several joins and is quite complicated to use through WP_Query. SELECT p.post_name, t.name as sname, t2.name as cname FROM wpw0_posts AS p INNER ...
1
vote
0answers
11 views

How to get only return parts of WP_Query result for performance?

I am building a leaderboard for users in my site. Each user will have a custom meta field, game_won. WP_User_Query will be used for sorting users based on the value of this custom meta field. As ...
0
votes
0answers
12 views

How can you include a link to a specific wp-query?

If im in a page of my theme, and using information on that page I construct an array of terms for wp-query, how do I create a link that executes that search?
0
votes
0answers
18 views

Why does this wp_query fail to show posts when 'category_not_in' is removed?

I'm trying to figure out this wp_query function for a site where a user can configure what posts are displayed on their page. This site pulls in blog feeds from other external blogs and has categories ...
1
vote
1answer
18 views

WP_Query filters

question might seem dumb but i truly didn't find helpfull links so im trying to do a simple query where i select the latest 10 posts and i want to be able to show only 1 post from those 10 in loop my ...
0
votes
0answers
17 views

SQL Joins not getting correct columns

I'm trying to alter the main query via posts_where & posts_join, in order to select the following: Orders (post-type) that have meta_key='_customer_user' that is >= 1 (can do this via standard ...
0
votes
1answer
19 views

Slick slider for post doesn't display anything

I want to make a testimonial slider with slick from https://kenwheeler.github.io/slick/. i use WP_Query for get the post with specific category. the slick works finde but it doesn't show the content....
0
votes
1answer
49 views

Display posts from multiple value in meta separated by comma

I have got main product with meta key: addons and meta values in this key: 129456,968945,495435 Each of these three numbers is the key with these meta values. For example: Post 1: meta_key: ...
0
votes
1answer
27 views

Access queried post ID in WP_Query

I'm trying to find out if it's possible to specify/define the currently queried post in WP_Query arguments, but having little luck. Not in the loop, but while the query itself is running. Specifically ...
0
votes
1answer
31 views

How can you get first post, last post and post count in a category?

I want to show information about some categories on my site, which would include among other things: A link to the first post in the category A link to the last post in the category The number of ...
0
votes
1answer
20 views

List taxonomy terms plus their latest post ordered by post date

I have the following code: $custom_terms = get_terms('columna'); foreach($custom_terms as $custom_term) { wp_reset_query(); $args = array('post_type' => 'post', 'posts_per_page'=&...
0
votes
1answer
45 views

WooCommerce. How To Exclude Subcategory Products From Category Listing Page

i found this code on other post, on youtube and git too.. https://gist.github.com/ibndawood/17ade59c2f856a59e42a5ebf91fbb357 https://www.youtube.com/watch?v=YOUkez45GEk Remove child products from ...
0
votes
0answers
27 views

WP_Query random ordering not working since 5.4

My random sorting of custom posts isn't working since I upgraded to WordPress 5.4. This is the query that I am using: $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args ...
0
votes
1answer
219 views

Php Trying to get property 'ID' of non-object

I am using this code in a page template to determine the custom post type and display a different template for each custom post type. if ( $query->have_posts() ) { ?> <ul id="floros"&...
0
votes
0answers
19 views

How to get post from all custom post_type multisite to the main site with pagination ordered by date?

Currently this is my WordPress Multisite: Main site -Sub Site -Sub Site -Sub Site -Sub Site and this is the example code for getting all post from multisite : foreach( $blog_ids as $id ) { ...
0
votes
1answer
72 views

What is the equivalent WP_Query of a SQL Query?

The problem There is a post_author post type, the main post relates to post_author: every post has one post_author. I need to have a list of all post authors to be sorted in a descending order by ...
0
votes
1answer
33 views

IF ( ! $loop->have_posts() ) condition doesn't work - WP_Query

So I'm almost positive I had this working perfectly, then somewhere out of nowhere it seemed not to. I've tinkered around and have had it hide everything and then hide nothing at all. Wondering if ...
0
votes
0answers
11 views

How the best way to get and publish single post from network in Wordpress Multisite and create permalink for it like “blog/%site_id%/%postname%”

My idea is collect post from subsites to main site in Network WP MS and open it there. I have found nice class https://github.com/miguelpeixe/WP_Query_Multisite for Multisite Querying. Now i want to ...
1
vote
0answers
27 views

How to filter, restrict and return posts based on custom user meta information

On this online platform project i have requested all users to add in their school title. In the user dashboard there is a posts section which currently shows all posts. I want to only show posts that ...
2
votes
1answer
50 views

Get image of latest post from taxonomies/categories

I have a custom post type "Artworks" with a custom taxonomy "Artists". I have a page where I list all the entries from the "Artists" taxonomy (Artist 1, Artist 2, Artist 3, etc.). How can I get the ...
0
votes
0answers
13 views

How to add an image dynamically to post title if it is published today or less than 2 days

I was trying to add an image like a "new" image to the posts which are just published and are less than 2 days old. I tried using a function like this within a WP_Query but it is applying to all ...
0
votes
0answers
26 views

Convert a custom query to a function and get a shortcode

I am a newbie with PHP and WP. This works but I would like to convert it into a function to call it as a shortcode in the middle of a post. How to "convert" this one? Thanks <?php // related ...
0
votes
1answer
31 views

create custom shortcode wp and put php code in

i use ACF plugin and i want put this query in shortcode. but i have a problem. (not output anything) add_shortcode('pishnahadi' , 'kn_inline_related'); global $post; function kn_inline_related( $...
1
vote
0answers
16 views

How To Remove/hide some specific categories from two different categories widget from sidebar

I have two categories sidebar widgets with different topics on my site. I want to hide some specific categories from each of the widgets. Is there any way to do so? Suppose I have total Categories ...
1
vote
1answer
214 views

Dynamic content based on a URL parameter

So, I'm doing some wordpress development studies and classes, and now I got an project to work on, and need to get the following task done: I'm doing a telecom website. The site has a page called "Buy"...
1
vote
0answers
22 views

How to change this WP_Query to get all ProductIDs and not only specific one?

I am using plugin FooEvents and want to export tickets attendees. But in the core files of the plugin, the export is only possible for 1 specific product. So if I want to export attendees for ticket "...
1
vote
1answer
20 views

category query for pages not working

I have added category support for pages in functions.php: function add_categories_to_pages() { register_taxonomy_for_object_type( 'category', 'page' ); } add_action( 'init', '...
1
vote
0answers
22 views

Is it a good idea to improve meta query performance by adding tax query?

I'm aware that using taxonomies over metadata is preferred when it comes to posts grouping. In simple words this and this are saying "use meta for unique data and taxonomy for repeating data(the one ...
1
vote
1answer
67 views

add active class based on permalink and url

i am facing a issue, on my wordpress site in left side i loaded post list with title and excerpt, and when you click on that content will get load on right side of page and its working fine but i ...
1
vote
0answers
27 views

How to duplicate 5 posts out of WP_Query results?

If I have done a posts query which has fetched a long list of posts in to the WP_Object $all_posts, how, during the output loop, can I pull the next five posts of $all_posts in to new WP_Object $...
1
vote
0answers
39 views

WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC

I'm trying to set up a query for an "event" custom post type that groups posts by year, with a heading for each year, in descending order; then, for each year group, ordered by date in ascending order ...
2
votes
0answers
33 views

How to output different posts per page?

I want to display one blog article less than on the following pages. The following code works but the the paginaton on the first page displays 1, 2, 3, 4 and on the next pages i get the correct ...
1
vote
1answer
59 views

How to display user order by role

I am trying to display user on query but i want to display order by user role. Suppose we have 2 user role, Gold and Free. I want to display Gold user first and then free users. $args = array( ...
0
votes
1answer
38 views

WordPress Query custom ordering by temporary variable

I have created location proximity functionality. I have a WP_Query loop created for a custom post type called Instructor. Each instructor has an address, so if someone enters a zip code it calculates ...
1
vote
1answer
75 views

Meta query with order by another custom field

Edit: I will try to explain in detail my problem. I am working on a portfolio site. There are a few custom post types: Projects, Publications, Exhibitions, Lectures and Slides. Home page consists of ...
1
vote
1answer
10 views

Display a specific category of products in shop page and disable code for specific actions

I want to display a specific category of products on the top page of the shop page. This was achieved with the code below. However, with this code, when searching for products from the search console, ...
0
votes
1answer
107 views

WP Job Manager plugin - Listing only the twelve job categories on frontpage order by jobs they have

i am using wp job manager plugin and i am trying to list on the frontpage only the twelve job categories according to the jobs they having. The job categories having more jobs go first. I managed to ...