Stack Exchange Network

Stack Exchange network consists of 175 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 a given request.

1
vote
1answer
15 views

Sort by two dates. Default entry date and custom field if present

I have a custom post type where there is an option to sort by date. There is however a custom date field that allows changing the display date. This custom date field is not always filled. Right now ...
1
vote
1answer
22 views

Display link to taxonomy archive only if it has posts with certain custom field values

Posts on my site describe future events, with the event date recorded in a custom field in Unix time. Generally, only upcoming events are relevant to visitors. As such, I'd like to display ...
0
votes
1answer
20 views

Loading two different AJAX requests on two different pages

I hav ebeen trying to call two separate AJAX requests, on separate pages, each pulling in their respective parts. Right now, it only pulls in ONE of the AJAX requests on both pages even with specific ...
-1
votes
1answer
27 views

First post in loop displays twice

I have created a wp_query where I change the post format after every 4th post. Unfortunately, the first post is displaying twice which is surely something wrong with my modulo conditions. I appreciate ...
0
votes
0answers
16 views

Woocommerce search pagination not working

I have a problem with the Woocommerce Pagination but only on the Search Page. On category sites the pagination links are working just fine. But on the Search Page the pagination generates links like ...
0
votes
2answers
23 views

Tell wordpress to show a single page instead of an archive page

my wordpress site urls like this: https://example.com/?pid=a125a5&lang=en and query of my archive page like this: <?php $the_slug = get_query_var('pid'); if ($the_slug){ if ( $post = ...
0
votes
0answers
16 views

Show Posts from Specific Category as the Picture Layout Style

I am Trying to do a layout to show posts from specific category. like that picture: i can do in query. but when client create a category and wants to display a layout like the picture. is there any ...
0
votes
1answer
14 views

Set “editor” role to existing user

Using the User ID of an existing user, how do I change the role to Editor? Here's what I tried: $wpdb->query("UPDATE wp_usermeta SET meta_value = 'a:1:{s:6:\"editor\";b:1;}' WHERE user_id = '$...
0
votes
2answers
26 views

How to order posts on each different category?

In wordpress, right now only on my main blog page, I managed to sort all posts with: <?php if ( is_active_sidebar( 'blog-category' ) ) : ?> <?php dynamic_sidebar( 'blog-...
0
votes
1answer
28 views

Only return taxonomies that are linked to a category & product

What's the best way, to return taxonomies, but only taxonomies that are linked to a product, within the category, I have a heirachial taxonomy, I want to get all the top level options, once an option ...
1
vote
1answer
39 views

How to get Metabox custom field to show checked if value is updated using post meta query?

I have two radio buttons as custom metabox fields for pages/posts. One radio button has the value of "enable" and the other has the value of "disable". My radio buttons will stay checked only if I ...
1
vote
1answer
18 views

What is the difference in a query when using a fieldname as a meta key vs orderby field?

I'm trying to figure out the actual difference in what is happening between these two args setups for a wp_query $today= date('Ymd'); $homepageEvents = new WP_Query(array( '...
0
votes
1answer
13 views

Order posts inside bootstrap card columns

I have a bootstrap 4 card columns masonry like grid. I want to show six posts form my articles and I'm using a custom query to retrieve the posts. All works fine, but the posts aren't showed with the ...
0
votes
1answer
17 views

How to display grandchildren only of custom post?

I am trying to display the grandchildren of a custom post type. The structure is is fairly simple: Issues Issue 1 Article 1 Article 2 Article 3 etc Issue 2 Article 1 ...
0
votes
0answers
22 views

how to get wp_query posts only first letter of alphabet A?

I want to get all the data by wp_query only the first letter of title specific alphabet 'A'. My code will be like: $the_query = new WP_Query( array( 'posts_per_page'=>10, ...
-1
votes
0answers
20 views

How do I add data from a MSSQL database to a Vehicle Listing Plugins DB?

How do I add data from a MSSQL database to a Vehicle Listing Plugins DB? I would like to find out how can I push data from my MSSQL database to a vehicle listing plugins database to keep the listing ...
0
votes
1answer
37 views

AJAX Breaking Offset Argument In WP Query

I have been using AJAX on my website successfully and for my category.php page I need to use the offset argument. Unfortunately, AJAX creates complications with offset and I get the same posts looping ...
0
votes
1answer
16 views

Exclude posts with specific metadata from search?

I have created this searchfunction that looks like this: function search_data_fetch() { $search_query = new WP_Query( array( 'posts_per_page' => -1, 's' => esc_attr( $_POST['keyword'] ), '...
0
votes
0answers
13 views

Check if a form has been changed after submit

I have a form where the user selects some options and some inputs then clicks on submit. After submit, the user will see the requested posts (based on how he/she filled the form). The problem is that ...
0
votes
1answer
33 views

How to get post by meta value

I am trying to get post of custom post type by two meta value but it does not work. I have followed lots of article but not worked below are my code. Note: 1. first meta value is a type of date eg: '...
-1
votes
1answer
15 views

Get Related Posts by Tag if Tag is Empty Get Posts by Category

I'm using Ajax Load More, and I'm trying to get related posts by tag. Which works: $terms = wp_get_post_tags($post->ID); // get current categories $term_array = []; // Create empty category array ...
0
votes
1answer
18 views

How can I use WP_Query to sort 'event' custom post type by date?

I have a custom query that in another iteration I'm using to only display events in the future: $today = date('Ymd'); if ( is_post_type_archive('event')) { $eventPosts = new WP_Query(array( ...
0
votes
0answers
9 views

pagination problem with changing $_GET

I have a select option and some inputs that are getting into the $_GET, then based on $_GET, the $args of wp_query(args) will be changed, everything is fine and pagination works good. but when i ...
0
votes
0answers
30 views

Sort custom post archives by a meta value from a different custom post type?

To make a long story short, I have a custom post type called artworks with these meta fields: title catalog_no artist_key I have a second custom post type called artists with these meta fields: ...
0
votes
0answers
16 views

pagination problem with select option

I have a select option menu and a wp_query. when a user choose an option, it shows related posts. everything is great but pagination. pagination is working good, it shows pages and when you click page ...
1
vote
2answers
108 views

Sort in WP_Query(), not filter? Is it possible?

I want to query and SORT in WP_Query(). But whatever I do, it only prints posts with meta_key set up. But I want all the results and just sort them. This is my query: $query = new WP_Query(array( '...
0
votes
2answers
30 views

WP_query only displays one of my custom post type entries

I create a custom post type and wrote a shortcode to display the posts on the front end of my website, but the code only displays one (1) post, and the most recent one. See front-end page here -> ...
0
votes
0answers
11 views

WooCommerce duplicate refund orders

I've created a query to search for orders based on custom order metadata, which works great! I then echo any data from the order I want to which is fine. However, I have a problem when I refund an ...
0
votes
0answers
18 views

can i add admin menu for set query category id?

I am thinking of something.that i want to add a wordpress admin menu for set category id. i mean i designed news section that lists post from specific category. like this: Sports News Post from ...
5
votes
1answer
41 views

Is it possible to select against a post's parent's fields with WP_Query?

I'd like to query post revisions using WP_Query for display on an admin page, and I want to include pagination parameters. I have two constraints: I would like to only retrieve revisions for ...
1
vote
0answers
18 views

Query to get siblings and parent page

I would like to create a custom query ID (to use in Elementor) to get siblings pages of the current page + the parent page of the current page. For now I get only siblings pages (without the parent ...
0
votes
2answers
20 views

Filter Custom Taxonomy Posts

I have a custom taxonomy page, it also has a slider up top. The problem is the slider displays random posts from all taxonomies rather than the current taxonomy. Is there a way to filter the images in ...
0
votes
0answers
19 views

Multiple Arrays for Custom Post Query using Boostrap accordions and ACF repeater fields

I'm trying to fix an issue that requires multiple array queries inside a loop. I'm no PHP whiz, but I got one part to work. I can't get the other part to show correctly. I'm using a collapse repeater ...
1
vote
1answer
44 views

Can't query tag and post_type at the same time

On my developer site this query is used for a carousel in index.php : $vedette_accueil = new WP_Query(array( 'tag' => 'vedette-accueil', 'nopaging' => ...
0
votes
0answers
18 views

Wordpress doesn't respect Page slug in custom post type url pagination. Keeps getting removed

I have a custom post type, Company, with respective company child pages. Whenever I attempt to go to a page url eg. http://example.com/company/example_company/page/2, the /page/2/ gets striped from ...
0
votes
1answer
21 views

How to display sticky post always at the top (before regular post) in wordpress?

I am working on a wordpress code as shown below in which the modified post displays at the top. $temp_args = [ 'post_type' => array('current-channel', 'post', 'current-episodes'), '...
0
votes
0answers
15 views

Change default wp-query using pre_get_posts

I would like to show all the posts of a post format on top of the default wp query and show all the other post formats below them (in the same query) using pre_get_posts. Please note that I need to ...
0
votes
2answers
30 views

WP_QUERY wrong ammount of posts

I have 16 published posts of type "portfolio". With the query below, "found_posts" is 16. Correct so far. I've set "posts_per_page" to -1 to see all of them. But only 8 of them get rendered. The ...
0
votes
0answers
29 views

Wordpress Query optimaization for slow query

I've WP installation with some 120K posts. One of the slow queries that frequently appear at @mysql-slow.log is below # Query_time: 1.744827 Lock_time: 0.000567 Rows_sent: 1 Rows_examined: 635732 ...
0
votes
0answers
14 views

Query for get the “Sticky post” of a CPT with 2 taxonomies

I am new in WordPress and I am doing tests, I have created a CPT called ('company') with two taxonomies ('zone' and 'sector'), I want to show me the companies with a certain sector (sector term such ...
0
votes
0answers
19 views

Wordpress - just refresh blog archive by new query

There are some ways to re-query main posts loop. For example - query_posts($query). Samples shown in Codex provide me with printing new stuff in cycle have_rows. Sorry, but I don't want print ...
0
votes
1answer
23 views

wp_insert_post with ACF Fields and WP Meta Query returns no rows until update

I’ve been reading a lot how you can’t use wp_insert_post and update_field because the field isn’t created yet or sum such, so I’ve experimented with MANY permutations of wp_insert_post. My field is a ...
0
votes
1answer
32 views

WP_Query, ACF field and array

First of all, sorry this title, I really don't know how title the question without write a blobtext! :) Anyway, my problem is this one: I have a custom post "Risorse" (en: Resources). It supports ...
0
votes
1answer
11 views

how to move a page from one drop down menu to another drop down menu

I have a page that is posted under one heading but I want to move the whole page to another drop down... for example from 'FOR SALE' drop down to 'RESULTS' drop down
1
vote
0answers
16 views

How can I use $wp_query->tax_query as tax_query parameter for a new WP_Query instatiation?

I am trying to use $wp_query->tax_query right out of the box as tax_query parameter, however I cannot work this out. The parameters for my new WP_Query is actually the same as the default query of the ...
1
vote
2answers
29 views

Get all Posts If has same custom field values in Posts

I am trying to get a list of posts if has same zipcode values. Thanks in advance for the help. <?php $query = new WP_Query( array( 'post_type'=> array('service'), 'posts_per_page' => -1, ...
-1
votes
0answers
26 views

Pagination not working in WP_Query

Pagiation function not working on custom WP_Query. Checked this solution and make same things. But my pagination not work $paged = get_query_var( 'paged', 1 ); $args_query = array( 'order' ...
0
votes
1answer
14 views

Woo Commerce using WP_Query to get products that match price range, with an additional required product attribute

I have code that successfully returns product within a price range. However, I need to also filter by a product attribute called 'size'. So I should get all products of a certain size between the ...
0
votes
0answers
11 views

Use Repository Pattern in WP theme

In my template files I have a lot of WP_Query to get posts of an author or from a specif category ecc... I'm thinking to use Repository Patter in order to have cleaner code and a layer between ...
0
votes
0answers
28 views

cron job for custom post type not working since Wordpress 5

Since Wordpress 5.1 (or 5 in general) I have a problem with a cron job. This cron top is filtering expired custom posts (coupon) and will mark it "not reliable" however its not working anymore. ...