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
772 views

Custom Post Type + Category archive

I have created a WP stack with 3 post types: 1. Post (default) 2. Event 3. Place These 3 post types share the same taxonomy, that being the default WP category, here are some example categories: ...
41
votes
4answers
118k views

wp query to get child pages of current page

Can anyone please help me to with the wp_query. I am making a template file/loop to create and archive page of the current page children pages. This query needs to be automatic as I am using in on ...
0
votes
0answers
1k views

Imported Content Doesnt Show Up On Frontend

I found similar problems posted couple times, for different custom post types, but none of the solutions worked for me and these, other questions, didnt have much info provided, I'll try to give as ...
0
votes
0answers
8 views

I want to display parent and child posts in a lists

I need display custom post type posts list same as menu till n level. Below is the flow chart how I need to display. Post 1 Child Post 1 Child Post 1 Post 2 Child Post 2(A) Child Post 2(A) ...
7
votes
6answers
14k views

Return parent post with its children using WP_Query?

In some cases it might be useful to use multiple post & page parameters in your WP_Query object. In my case, I would like to display children of a parent page including the parent page itself. ...
0
votes
1answer
4k views

Why does 'exclude_from_search' exclude a custom post type from WP_Query?

In WP 3.1, it appears that setting 'exclude_from_search' = TRUE for a custom post type excludes the post type not just from searches on the front-end, but also from any post query using 'post_type' = '...
0
votes
2answers
828 views

Conditional posts in WP_query for search

I have a custom post type that im trying to limit results in search. The CPT is a deal/coupon, with a start and end date for each of the deals. What I'm trying to do is only show these posts in ...
0
votes
2answers
1k views

Masonry layout within the loop

I have tried to to make a custom query, to some extend. it is working fine. But where i cannot make it work, is it to break after every 3 posts and do same thing (print div.row) and run same loop, For ...
0
votes
0answers
14 views

Wordpress primitive query returns = array

i am trying to primitive query form this wp_query: $query_v = array( 'post_type' => array('pro'), 'posts_per_page' => -1, 'orderby' => $count_visit, 'order' => 'ASC', ...
0
votes
0answers
8 views

Catalog page filter by through url?

I am trying to get some custom parameters in the catalog page (archive.php) query. Like I can filter with attributes. For example, this works with the built in filter products by attribute woocommerce ...
1
vote
1answer
37 views

Having trouble with custom date field for CPT query (Wordpress)

I've read as many of the questions and answers on here as I can find and none of the solutions are working for me. No idea what I'm doing wrong here. I have a CPT 'event' with meta key 'start_date' - ...
0
votes
1answer
14 views

How to display all posts not in a post_format

Using WP_Query() I want to display all posts -except- those with the 'image' post_format. I tried this, but it did not work. $args = array( 'relation' => 'NOT', 'tax_query' =&...
0
votes
1answer
8 views

Displaying all posts from other sites on the network on one site

I have a multi-site setup as follows Main Site has no posts Site A has 1 post A Site B has 1 post B Site C has 1 post C What I'm interested in is to be able to treat the main site as an aggregation ...
0
votes
1answer
25 views

Sort by price wpdb

I have a page on my wordpress to search for tires everything works fine but I would have liked to know how to add an extra column to sort them also by price. They can already be sorted by size and ...
0
votes
0answers
11 views

Wordpress Query for CPT that only shows posts within radius of current user's geolocation

I have a CPT called medical_providers. Each medical provider has two ACF meta_fields (latitude and longitude). I want to write a wp_query to only show medical providers that are within a certain range ...
0
votes
2answers
892 views

insert thumbnail image from php script

I'm trying to insert a post image thumbnail from my php scritp. It's inserting the post, the content, a download link, and I only need to set the thumbnail image to finish my script. This is my code ...
0
votes
1answer
598 views

Order posts by custom column using pre_get_posts

Is it possible to sort posts by custom column in wp_posts table (in this case, 'fav_count' column) using pre_get_posts filter? If not, is there any other way to do this before the main query is run, ...
1
vote
1answer
40 views

Filtering posts from different categories into different section by doing WP_Query only once

I am trying to create a custom homepage with multiple categories section. I know this is possible with WP_Query, but i don't want to make multiple db trips. I want to query posts (say 5 each) from ...
0
votes
0answers
11 views

Order category in shop page

i have this function to order for category the shop page in woocomerce function so_27975262_product_query( $q ){ //$q->set( 'category__in', array(96,105,97) ); if( !is_product_category() ) { ...
1
vote
3answers
880 views

Why does get_posts only show results for Admins or logged-out users?

I use a get_posts() call with these arguments: array(6) { ["include"]=> string(14) "1633,1634,1635" ["post_status"]=> string(3) "any" ["post_type"]=> string(10) "attachment" [...
1
vote
0answers
20 views

Wordpress Query is taking more then 20 second and stuck on creating index

Hi I need help with below query this query takes around 20 second and when more then one is executed then server CPU usage hits 100% and server stop responding. here is the query from process list. ...
1
vote
0answers
17 views

How to figure out redirection and contents in hybrid solution containing word press content and legacy code (ASP.net)

I have legacy solution(ASP.net) hybrid with wordpress content, I have access to my ASP.net code base but not wordpress content. How can I figure out which section in my site is served through ...
0
votes
1answer
637 views

Randomly select one of last 3 posts

ok so i have this: $args=array( 'orderby' => 'rand', 'order' => 'DESC', 'posts_per_page' => 1, 'offset' => $offset, ); $q = new ...
0
votes
2answers
813 views

How to fix pagination for custom loops on front-page.php

A search on this topic on this site throws up a lot of results claiming to have resolved this issue, but I am having a contrary experience after implementing these guidelines as outlined here: How to ...
2
votes
1answer
23 views

How can I use WP-CLI commands without --allow-root

I wanted to use WP-CLI commands in my putty WordPress 5.5.1 & Ubuntu 20.04 Droplet but “When I use Wp commands without –allow-root then It shows an error that you are accessing as the root user,” ...
1
vote
1answer
28 views

Sort wordpress custom posts based on meta value

I'm trying to sort the custom posts based on meta value as priority level1, level2 and level3. I have given a dropdown field in post meta as featured posts, standard posts and basic posts. I want to ...
0
votes
0answers
21 views

SQL to join u3g_users & u3g_meta_value with repeating data

I'm using the below SQL to create a table from wordpress user information joining data in u3g_users and u3g_metavalue. SELECT u3g_users.`ID`, u3g_users.`display_name` AS `Name`, ...
0
votes
1answer
699 views

Custom taxonomy and query multi conditions

I have this query $query->set( 'tax_query', array( 'relation' => 'OR', array( 'taxonomy' => 'location', ...
0
votes
1answer
1k views

Exclude a Woocommerce product from WP_Query

I'm using a WP_Query for get products from categories, $default = array( 'post_type' => 'product', 'orderby' => 'date', 'order' => 'DESC', 'post_status' => 'publish'...
2
votes
1answer
3k views

Display related products with custom output

I'm trying to display the related products with my custom html output, unfortunately i'm kind of lost on how to do this. The WP_Query below displays the products that are in stock, what i want is to ...
1
vote
1answer
822 views

Why is wp_query causing an uncaught error to is_user_logged_in() not defined?

I am building a plugin and have used the simple query: function getTotal($postType){ $total = 0; $args = array( 'post_type' => $postType, ); $metrics = new WP_Query( $args ); ...
0
votes
1answer
2k views

WP Query - Search in title or author_name

My need is to have a WPQuery that searches for posts which title is 'test' OR author_name is 'test'. Here is the code I tried: $search_query = get_search_query(); $args = array( 'relation' =>...
0
votes
1answer
38 views

WP_Query for a taxonomy value OR a custom post type meta field

I have a custom post type 'csl_playlist_manager', and one of its meta-fields is 'available_to_all'. I also have a custom hierarchical taxonomy, 'csl_source', which identifies the owner of each ...
0
votes
1answer
1k views

Checkbox field that add a subscription product and change prices of other products in checkout and cart page

In Woocommerce checkout section, I am trying to add a checkbox that adds an additional subscription product. It is working fine and I took help from here One more requirement is that if there are ...
0
votes
1answer
735 views

Posts loop with pagination on a single post page

Today, I need your help. On my pages I have a sidebar with : <div class="sidebarActu"> <ul> <?php $i = 1; while ( have_posts() )...
0
votes
1answer
658 views

Selecting posts older than the current Unix epoch timestamp

I am trying to perform the following query, which originates by the fact the post's 'date' and 'time' are entered as separate custom fields. $args = array( 'post_type' => 'some_kind_of_posts'...
1
vote
1answer
34 views

Include Sticky Posts with Custom Query

I'm working with Custom Query in WordPress, Basically, I'm showing 4 most recent posts of a category having ID 4 and my query is as follows:- $args = array( 'post_type' => 'post' , 'orderby' =&...
0
votes
1answer
24 views

WP_Query to output chosen term and posts with no term assigned

I'm trying to build a query to filter a list of employees by a location taxonomy. Some staff are fixed, in that they'll only ever work out of a single office, but others are flexible and work from ...
0
votes
0answers
37 views

Posts per Page not working

I have custom post type of reviews, I want to limit the number of posts on the page, the standard methods do not work, please help! <?php get_header(); ?> <div class="container ...
0
votes
1answer
744 views

Pagination is not working on custom query inside a custom home page template

I know this is a duplicate question. But to comment on existing question, I dont have enough points. So here we go.... Pagination is not working on custom query inside a custom home page template. ...
0
votes
1answer
732 views

Sort by custom field that is an array?

is it possible to sort posts inside a query based on post value that is in an array - but using the last element of the array? The code looks something like: <?php $mostsharedposts= new WP_Query(...
0
votes
1answer
16 views

How to make WPQuery custom post type work in Twig / Timber

Im totally new to Twig and Timber. I was reading their doc and watch some tutorials however I cannot get it to work. I have this WP Query with custom post type and ACF field: <?php $...
0
votes
1answer
28 views

Custom post type and standard post not displaying or working

I want to display 5 images of custom post type 'project' and 1 standard post in the front-page. I have tried to merge both queries in one, however its not working. FYI: I have set the theme support ...
0
votes
1answer
878 views

Query Pulling the same post twice

After seeking help and failing, I managed to write a query for Wordpress that does exactly what it's suppose to do, however it pulls the post that it's suppose to in twice. I've stared and stared at ...
0
votes
3answers
577 views

WP_Query returns empty if meta_query has more than 7 values

I have a custom loop to display a custom post type 'properties' . The idea is to search properties based on different search parameters selected by users. Now the weird problem I am facing is that if ...
2
votes
1answer
742 views

Wordpress WP_Query orderby being overwritten

$args = array( 'post_type' => 'mcm_company', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => '1000', 'post_status' => 'publish', )...
0
votes
1answer
11 views

WP_Query Results Issue with ACF

I have the following query set up $argsar = array ( 'numberposts' => 1, 'post_type' => 'auctionroom', 'meta_key' => 'auctionroom_username', 'compare' => '=', 'value' => $...
0
votes
1answer
563 views

WP_Query showing all posts, except from category X, unless it's also in Y

I'm trying to show posts from categories A, B, C, D...and Y, except X, unless posts in X are also in Y, then show them with the rest. I can hide category X on it's own pretty simply: $args = array( ...
0
votes
1answer
855 views

WordPress: Cron locking and Queue

I have some CPU intensive scripts that I don't want to run concurrently. Every now and again the scripts will overlap and crash the server. Already at 2GB and the mysql container still crashes. I ...
1
vote
1answer
832 views

Wp query show post by author name or post title or post content

I have to create a search query which allows me to filter all posts where author name and post titles or post content has the word from search textbox. So if i search wordpress it should list all the ...

1
2 3 4 5
104