Questions tagged [query-posts]

Set up The Loop with query parameters. This will override the current WordPress Loop and shouldn’t be used more than once. This must not be used within the WordPress Loop.

Filter by
Sorted by
Tagged with
0 votes
1 answer
23 views

How do I exclude the current post from the upcoming post query

Summary: I have a page template with 3 queries. Current Exhibition Upcoming Exhibition Past Exhibition The dates are custom fields. The problem I'm having is, how do I dynamically exclude the ...
0 votes
0 answers
31 views

/page/2/ redirect to 404

I make a filter form in the category page and get parameters with get_query_var, my problem is in the Pagination when the user filters a parameter and wants to go to page 2, it redirects it to 404 ...
0 votes
0 answers
9 views

How to get recent one post from each category on home page?

I am trying to display one post from each category. I currently have five categories, with two parents and three children. Animal, -Cat, and Home —Water Filter -Kitchen. Code have error if any recent ...
  • 9
0 votes
0 answers
14 views

Trying to set up a range filter for related custom post types

I have set up two CPTs, "Property" and "Suite". Each Property has a number of Suites assigned to it via an ACF bidirectional relationship.  Each suite has a set size (in square ...
-1 votes
1 answer
25 views

Show number of posts AND number on current page (cannot make it work)

I have looked over the following but still cannot make this work; Show number of posts AND number on current page Show number of posts and number on current page (revisited) This is what I currently ...
0 votes
0 answers
15 views

Group custom taxonomies based on tags contained in their posts

I have a piece of code that shows links to children of a parent taxonomy on archive pages. My goal however is to separate these children into groups, based on the tags (standard WordPress tags). My ...
  • 43
0 votes
0 answers
18 views

Word count for all posts of all authors

I currently have 11 posts and the total word count shown in the Gutenberg editor after clicking the “i” icon above the writing area is 2,342 words. I manually added it up. The words in the title are ...
0 votes
1 answer
24 views

Count words for all posts by all authors

So I got this code from another query and it works for one single post. However, I want to show the total words of all the published posts by all authors. How do I modify this or is there a wp ...
0 votes
0 answers
18 views

'Active lotteries' only custom query for woocommerce lottery plugin and elementor

I am wanting to create a custom query that returns only active lottery products on my lottery 'style' website. I have been given a query but I am not sure where this query should be placed in my ...
0 votes
0 answers
5 views

Quering array of post types & pagination. Articles are repeating sometimes on different pages

I am doing some page with filters and spotted interesting bug (is it a bug??) related to quering articles (posts). In my case I want to output default “post” articles and my custom post type “blog”. ...
0 votes
0 answers
8 views

Do I need to create a multisite for querying posts from multiple WordPress sites?

I have an existing WordPress site at (example domain: XYZ/test). I want to host two more WordPress sites in subdirectories, e.g. XYZ/foo and XYZ/bar. Both XYZ/foo and XYZ/bar will contain different ...
  • 1
0 votes
1 answer
94 views

Display ACF object field data using Elementor Custom Query

Hello i'm working on a website using elementor pro + ACF. I have create a custom post type (CPT1) with ACF object field that take another CPT2 as values. I would like to display on my CPT1 page all ...
0 votes
0 answers
50 views

How to detect if the ajax_query_attachments_args was triggered to set the featured image?

I'm trying to filter the attachments when the user tries to set a featured image for the current post, but this affects all the ajax_query_attachments_args hook requests, like the one in the upload....
0 votes
0 answers
67 views

Optimising WP_Query with ACF Fields

I am wondering if it's still possible to optimise the WP_Query or also if there's another way of doing it. I have the post type and a custom post type called case-study which gets displayed on the ...
0 votes
1 answer
15 views

change the default order of posts only for specific categories

I want to change the default ordering for posts, to last modified date, but only for certain categories pages (when visiting certain category pages) I have this function code, which is working, but I ...
  • 167
0 votes
0 answers
312 views

Elementor posts custom query based on tag [closed]

How can I filter the Elementor Posts widget with a custom php query that returns posts with a specific tag attached? I want to do something similar to this: function my_query_by_post_types( $query ) { ...
0 votes
0 answers
121 views

Custom Query: Multiple CPTs and a taxonomy filter

I want to create a post feed that displays the following: ALL posts in the CPT 'custom_post_type_1' Any 'post's in the category 'speakers' So far, I have this filter which displays all posts in '...
  • 1
0 votes
0 answers
135 views

Query post and sort by custom value calculated with custom field on cpt

I shall made a query post ad I have some issue to sort the posts. I have multiple custom fields that calculated in php (with some operators) a final value for each posts - I call it $price. These ...
  • 1
0 votes
1 answer
40 views

How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]

I am using ACF Pro to make a relationship between two custom post types. One CPT is a thing and the other is a Container of Things. I need to solve the issue of things within a container of things ...
0 votes
0 answers
20 views

WP query_posts group by meta field related

Hello Guys i am trying to customize a wordpress theme and am getting this is How it queries All Posts with episodes post_type. My Question Is. this Post type is related to another post_type which is ...
0 votes
1 answer
42 views

Conditional operator OR not working with custom fields

OR operator is not working for both conditions, only check first value if true then code executed and if first is false then not check 2nd condition and return else output. I also try with LIKE ...
  • 37
0 votes
0 answers
8 views

AWS usage queries

1.We are hosting multiple Wordpress websites on Aurora database. We develop the sites in a subdomain and when go live we just rename the subdomain to the actual domain and make the necessary changes ...
0 votes
1 answer
100 views

complex get_posts() query to select child pages

I have pages on 2 levels under the main deparments page like below. Departments --Department 1 -----Course 1 -----Course 2 --Department 1 -----Course 3 -----Course 4 --Department 3 --Department ...
  • 31
1 vote
0 answers
15 views

How can I create 'future' and 'past' parameter for restAPI by filtering the CPT custom date field by greater than / less than current datetime?

add_filter( 'rest_events_query', 'filter_events_by_date_field', 999, 2 ); function filter_events_by_date_field( $args, $request ) { if ( ! isset( $request['filter_date'] ) ) { return $args; } $...
  • 11
0 votes
0 answers
27 views

search.php to search only the post title

I'm trying to rewrite my search.php to search only for the post titles because I have a ton of posts published to my site (around 400k), which slows down the search speed to about 20s per search. <?...
0 votes
0 answers
15 views

returning the currect URL for nested posts

I have a posttype called (article) witch have a meta_key called (parents_ids). So the article can be related to multiple articles. I want to return the currect URL depending on the parent post For ...
0 votes
1 answer
75 views

Change the destination of the URLs in post.php

The post.php screen lists posts vertically in the admin area [and other post types]. Each item's post_title is a hyperlink, directly above some inline choices. Both the title link, and the "Edit&...
  • 483
0 votes
0 answers
32 views

Hot to check if new posts have been published since page load and notify online users?

I want to show a div notifying online users that there are new posts since they have accessed the page, in the index and also if new posts have been added in the category or tag they are browsing. I ...
0 votes
0 answers
31 views

Pull in posts using post meta for REST API

So I wasn't able to find much detail about this, so I wanted to ask the community to see if I can get an answer. So let's say that I have the following: $this->global_endpoint = 'https://example....
  • 1
0 votes
1 answer
30 views

Include current post into loop

I have a related posts loop ( in every single post page ) based on post title. source : https://wpza.net/get-related-posts-based-on-the-posts-content-in-wordpress/ But I also need to include current ...
0 votes
1 answer
148 views

Filter products on category AND tag

I want to be able to filter products based on category AND tag, as well as sub category AND tag. From my research I heard that I must write some kind of rewrite rule in functions.php for this to be ...
0 votes
0 answers
90 views

Sticky posts limit query and pagination for a custom post type

I would like to display 9 posts per page. But, when I have a sticky post, I would like it to be integrated in the 9 posts in the query. And, then, for the second page, I continue to have the next 9 ...
  • 1
1 vote
0 answers
32 views

Serve specific "template" page at any URL that ends in its slug

Still new to WordPress, so please go easy on me. Goal: Prevent users of a specific role from viewing other custom post types made by users of same role. Intended solution: Modify the URL and redirect ...
0 votes
2 answers
114 views

Move position in post list for a custom checkbox column

I have made checkboxes to every post in post list. Question: How can I change the the position for the new column. Now it`s at the right side of the post list. After "Date". How can I move ...
  • 21
0 votes
0 answers
38 views

Change pure SQL database query to WordPress post query?

I am trying to query posts that are nearby a given (lat/long) location. I have found this working SQL query, but this won't provide me flexibility to alter the queried later on, since I am not really ...
  • 230
-1 votes
1 answer
94 views

Wordpress pagination returns the same posts

I did search the other posts here related to this problem, and tried all of them in my case, but I can't seem to make it work (probably because I don't know enough code) Can you please help me with ...
  • 167
0 votes
0 answers
39 views

Counting post and changing roles in mysql database. Query not code

Hello I'm struggling to find an answer talking specifically about counting post and changing roles but on mysql language not php in the wordpress source. I'm not creating a plugin neither I want to ...
0 votes
1 answer
48 views

Why does my WP_Query pagination on a custom page.php only loads the homepage?

What I am looking to do: Setup WP_Query pagination in a custom php template file with a custom WP_Query query (It's not originally mine, I'm just fixing it). The file loops through posts (category &...
  • 3
0 votes
0 answers
44 views

Query post ordered by meta value that show first post that contained a tag

I have a query post for my CPT 'listing' that order posts by value of price contained on meta key. Now I'd like to add the possibility to show in the loop first posts that has a specific tag (o ...
  • 51
0 votes
0 answers
69 views

Facing problem with tax_query results

I need to get search results for posts on the basis of post-category(must) and posts-tags(optional). The process is like: search for a string e.g. "bananas" the category is always static ...
0 votes
0 answers
44 views

How do i create a custom post query when the meta value is an array?

A number of properties have been imported from an external API and saved into a custom post type called 'Properties'. I want to filter these properties by the city they are located in, however it is ...
  • 1
0 votes
0 answers
456 views

Custom post type archive page filters

What is the proper way to filter my custom post type archive page by my custom taxonomies? When i go to archive page(archive-recipies.php), fetch me all the post under the custom post type. In this ...
0 votes
1 answer
84 views

Get posts that do not have the same tags as current

I'm trying to get all posts in a custom plugin loop that DO NOT share the same tag as the current one. I'm trying: $events = tribe_get_events([ 'start_date' => 'now', 'eventDisplay' =&...
0 votes
1 answer
106 views

Get a Post Loop based on Logged in User information into a Shortcode

I have a follower button on users profiles where users can follow other users. I have a page template that shows all posts by users the currently logged in user follows. I would like to create a ...
  • 7
0 votes
1 answer
86 views

How to obtain the recent posts without their content in an efficient way?

It would be great to make a single DB request but I don't know how to do that either. I have this code and it works but I want to change it to be more efficient: $cs = get_categories(array( '...
1 vote
0 answers
27 views

Set multiple Post Terms in same Taxonomy

I'm having a hard time trying to figure out this problem. I have looked at various StackExchange threads but nothing seems to work. Long story short. I have a custom table that updates every day which ...
0 votes
0 answers
156 views

WordPress create custom XML RSS feed template

I am trying to create a custom XML RSS feed. However, my code is not quite working as expected. Here is what I have done: In functions.php I have created the feed called "top": add_action('...
0 votes
0 answers
66 views

Global $post returns 2 objects for my shortcode

I made a shortcode, it does most of what I need it to do. Except for a filter I need the post id of the page the shortcode is placed. (to get some linked custom field values) And I can't expect the ...
  • 11
5 votes
1 answer
2k views

WP 5.8 "Query Loop" block: where to place custom query?

In the recent wordpress.org article outlining the new Query Loop block, it says the "Inherit query from template" option allows you to "customize the query that the loop relies upon ... ...
1 vote
1 answer
314 views

Query with a meta value inside a given range

Quick question: I would like to retrieve some pages/posts with a meta value inside a range, eg) $min<$meta_value<$max for ordinary $meta_value there was a way to get pages/posts like this: $args ...

1
2 3 4 5
25