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

Order by terms for specific custom taxonomies

I am using the following code to try and order property listings by state for For Sale and Sold custom taxonomy terms $terms = get_terms( 'state' ); // $terms = get_terms( array('status', 'state' ...
0
votes
3answers
24 views

infinite loop in wp_query using simple query

This code goes into an infinite loop! What am i doing wrong? There is only one post called “hello there”. The only way to stop it is use break; in while. Any help appreciated $gotop="hello there"; ...
0
votes
1answer
31 views

Query against multiple locations within single custom post type post

I have a custom post type for "Events" and each event can have a variable amount of "Locations" (lat/lng) which is stored as meta. I need to be able to get "Event" posts based on the bounds of a map. ...
0
votes
1answer
92 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'...
0
votes
0answers
17 views

Upsells and Cross Sells replace with category

Greatings, I have code witch replaces upsells with category, how can i make that also Cross Sells will do same function? Adding code add_filter( 'woocommerce_product_get_upsell_ids', '...
0
votes
1answer
32 views

$wpdb insert is not work

I try different way for insert data in custom table but is not work and there are not errors. Sometimes is save, but most of the time is not. I check around the web, but no solution is working for ...
0
votes
1answer
34 views

How to Display Shortcode in the correct location, currently displaying before content after Page Title?

I am having an issue displaying the shortcode in the correct location when using a display child pages query. Can someone fix this for me? Thank you! function show_product_pages() { global $...
0
votes
0answers
25 views

Custom meta fields not showing up in WP_Response Object via custom endpoint

I created my own Custom Post Type called person and a corresponding end route. I can modify my posts with the endpoint, using functions as wp_update_post,wp_insert_post and get_posts. I am facing a ...
0
votes
1answer
32 views

Posts not showing per category after WP_Query?

I have a Query that goes in and should list all the categories for a post type and loop through and display all the posts within that category but I can't get it to work, it shows the posts in a ...
0
votes
0answers
33 views

Combine custom post loops to display all on one page

My site contains posts separated into 6 categories. Each category has it's own page with a custom loop on each page displaying posts from the respective category. I would like to consolidate all ...
0
votes
0answers
11 views

Upsell product as category - Exclude some categories

Greatings, I've reached what i needed to do - Is replace Upsell products with Category insteed of taking time to add upsells i just maded auto from category. But i've reached the end of the road. I ...
0
votes
1answer
37 views

Fix wp_term_relationships slow query in get_posts

I used the Query Monitor plugin to find slow query on my WordPress site. The below-mentioned WP_Query->get_posts() takes about 0.3446 query time out of the total Database Query time of 0.3976. ...
0
votes
1answer
44 views

WP ForLoop to compare meta information of posts to determine what post to display

The short of what I am trying to do here is: I want to display only one post based on a date stored in a custom field. I only want to display the post if it meets two conditions 1: The date needs to ...
0
votes
1answer
52 views

query posts in functions.php and update a field

I'm having problems querying posts in functions.php. This is mainly to update posts in the back-end, not to show a query on the front end. I'm trying to get all posts that use the status post format ...
0
votes
0answers
19 views

Error in the page of a CPT file in WordPress

I have a CPT of podcast type implemented in my WordPress. I had to do a type 301 redirection since the plugin that manages the podcasts (Seriously Simple Podcasting) did not let me modify the ...
1
vote
0answers
26 views

wp_query exclude word and category

I am trying to exclude word 'Vape' and exclude category using wp_query. Is it possible? $args = array( 's' => '-Vape', 'cat' => '-62', 'posts_per_page'=>'16', 'paged'=>$paged, 'orderby' =...
0
votes
0answers
25 views

Is it possible to custom set query for a WordPress REST API response?

I have a custom post type that I am querying for through WordPress REST API, right now the response returns all the posts. I would like to set the tax_query argument based on the user who is sending ...
0
votes
0answers
74 views

WooCommerce Custom Query with high/low pricing and paging

I created a custom query in my template to show certain products. I would like to add a sort feature for pricing ascending and descending but have not had any luck. Here is my code on my template: &...
0
votes
1answer
15 views

Query a Custom Post Type using SELECT that has ACF fields to compare dates

So I have a CPT called ads that has ACF fields of ad_start_date and ad_end_date. I am trying to write a custom WP query using a SELECT statement instead of using WP_Query because I am return an ajax ...
0
votes
1answer
11 views

Order by meta date with a thousanth of a second defaults to post order

I have a custom post type query: $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args = array( 'paged' => $paged, 'post_type' => 'my_custom_post_type', '...
0
votes
0answers
35 views

wordpress $wp_query->query_vars[ 'page' ] query to fetching url data

I have 2 wordpress pages template pr1.php and pr2.php . The pr1.php has links below that sends data to pr2.php as below 1st: https://my_domain.com/pr2/683/ 2nd: https://my_domain.com/pr2/683b/ 3rd: ...
0
votes
1answer
26 views

Using post_where filter only on main query NOT sidebard new WP_Query

I have a post where filter set up for a CPT archive page. Which works great but i have other WP_Query objects in the sidebar that dont work because the post_where filter is effecting those Objects ...
0
votes
0answers
21 views

Custom query for custom post type not getting correct post ID

I have written a custom query here: <?php $the_query = new WP_Query( array('post_type' => 'video', 'posts_per_page' => 10, 'post_status' => 'publish') ); ?> <?php if ( $the_query-&...
0
votes
1answer
30 views

How to merge these two post queries?

How can I consolidate the queries below... ? Query 1: Any posts with the "Topic" taxonomy term, eg. "Music" Query 2: Any posts attached to a "Company" taxonomy term, eg. "Spotify", which itself has ...
0
votes
0answers
58 views

How do I use $wp_query->current_post with get_template_part? I'm trying to add post classes (first/last/even/odd) to custom loops

... but $wp_query->current_post and the like don't work when I use get_template_part to pull in content.php files as modeled by themes like twentynineteen. The variables don't carry over I guess? Is ...
0
votes
0answers
23 views

How to include custom post types and custom taxonomies with WP_Query

Hi guys there any way to include or join custom post types and custom taxonomies with WP_Query below? static function &get_wp_query ($atts = '', $paged = '') { $args = self::...
0
votes
0answers
22 views

Lazy Loading using Pagination

im doing a lazy loading with WP_Query Pagination it's working fine but the content duplicate itself when it reaches it's end here is my code lazy-load.php <?php add_action('...
0
votes
0answers
15 views

How to store value in some variable in wordpress?

please help me I am new in WordPress the task is I have a URL like this http://localhost/talha/?aid=1 I want to store that URL value in a variable and use it through all my website. I read many ...
0
votes
1answer
20 views

How to avoid bypass of search bar rules?

I’m building my site locally. Since I want users to be able to write only specific terms in the search bar, I put a jQuery script in the wp-content\themes\sitename\js folder. The script works fine, ...
0
votes
0answers
11 views

Loading Youtube Video Methods

I have a post grid where i can make the youtube video grids but if loaded directly it results in a very slow website. Also ends up javascript render block. In WordPress how can this be handled? Is ...
0
votes
1answer
44 views

Why pagination is not working with tax_query param?

this is my query: $p_query = new WP_Query(array( 'post_type' => $post_type ,'post_status' => 'publish' ,'posts_per_page' => $per_page // 6 ,'paged' => $page // 2 ,'...
0
votes
1answer
33 views

Yoast primary category query modification

I have a problem with Yoast and displaying my primary category alongside rest of the posts from that category. Let's say I have 4 posts, all of them are lorem category and one post has set lorem as ...
0
votes
0answers
36 views

Translating WP query into to SQL query

I have very complex wp query and I want to use sql query instead of this. Is there any way to translate wp query to sql query. I am thinking that I will have a better control over sql query as the wp ...
0
votes
0answers
19 views

Remove post name of custom WP_Query when using in pagination?

Is this possible? I am trying to get pagination working on my pages and single pages. It seems like it's working, as it recognizes how many pages there are and shows the URL. The problem: the URL is ...
0
votes
2answers
15 views

List all ACF field values across every post on one page

I used an ACF repeater field for data sheets/instruction manual download links of products in woocommerce. There's 50 products and each has 1 to 4 download links on their product page. I've been ...
0
votes
1answer
22 views

Returning a custom content types with meta values

I find myself facing a situation where I will have a bunch of custom post types and I want to select those with specific meta values. There is a slight wrinkle in that the value I want to select ...
0
votes
1answer
24 views

How to invoke a HTML custom button based on a HTML dropdownlist menu

I am a WordPress beginner and want a help I created a HTML dropdown list like this: <select name="DropDownList1" id="DropDownList1"> <option value="select you location">&#xf015 ...
0
votes
1answer
35 views

Display the search results like the original pages

I'm creating my site (locally) and I'm using the starter theme underscores.me I created few pages using bold, italic, and other text styles, but I noticed that in the Search Results page, the content ...
1
vote
3answers
44 views

List of the years with posts presented

I need to get a list of the years with posts of given category. Like this: 2008, 2009, 2010, 2012, 2013 (if there were no posts in 2011, it's not included). I try this query, and it works — I get my ...
-1
votes
1answer
23 views

Get users query makes the site loading time too big?

I'm trying to get the top 10 users in (specific roles) by the highest post views, but this code makes the site loading time too big, and I don't know why! I'm highly appreciated your help. <?php ...
0
votes
2answers
84 views

meta query multiple values for the same key

I'm trying to query wordpress with multiple values but it looks like it can't take no more than 4 keywords I'm currently using a loop and I already tried to switch to a IN operator but I need the ...
1
vote
0answers
41 views

Removing noindex posts from wp_query

I have a blog website with some old posts and they appear in my "featured" posts section. I put those posts with noindex and but they still show up. is there a way to remove them from wp_query?
0
votes
1answer
73 views

Problem with get_page_by_path() using with WP_Query

I get error when i use get_page_by_path() with WP_Query in a php class. I use after_switch_theme and switch_theme in that class. And while the theme is activated then everything is fine as expected. ...
0
votes
0answers
68 views

Wordpress search query, how to modify the sql

I have a problem with the query search, which means I would only look for posts with post_status = published. The problem is that after adding my conditions, wordpress writes an "OR wp_terms.name LIKE%...
0
votes
0answers
8 views

Connecting from WP with WPML plugin to another WP db without WPML plugin

I am connecting to another Wordpress instance (using same database but different table prefix) from my main Wordpress site. My main wordpress site has WPML plugin activated but second site has not. I ...
0
votes
1answer
397 views

How to get top rated posts using wp query?

I want to get top rated posts using wp query. The rating value is store in comment meta database table when some one post a comment on wp post or cpt.Please screenshot EDIT Here is my code ...
0
votes
1answer
24 views

Pagination on archive.php not working?

My pagination isn't working for my archive.php, which I'm using as a template for my blog post categories links. <div class="row"> <?php $the_query = new WP_Query( array( ...
0
votes
1answer
12 views

Wordpress wp_query() basic question about args

Can someone tell me the comparison of these three query statement: 1/ Is it nline code ? I don't know what is it call. $getposts->query('post_type=projects&taxonomy=projects_categories&...
0
votes
0answers
28 views

Modify post image in full size

I have a website where the client attached many “full size” images to posts, most of them in 5000px width, is it possible to run something for resizing those images to large? Instead of going through ...
1
vote
1answer
21 views

Custom WP Query on custom meta and sort by multiple meta keys value

I am testing something out and I have a query like this: $paged = 1; $filter_min_price = 5; $filter_max_price = 300; $products5_cat_term_id = 368; $filter_brand = "Now, Garmin"; $sort_order = "ASC"; ...