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
27 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
19 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
15 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
13 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
36 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
39 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
55 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
18 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
16 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
25 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 ...
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
65 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
12 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
25 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
12 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
21 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&...
  • 465
0 votes
0 answers
29 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
26 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
23 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
40 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
48 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
0 votes
0 answers
16 views

Custom wp-query display post only today

I have a problem. My query not display the post only today. $today = getdate(); $query = new WP_Query( array( 'post_type' => 'tips', 'posts_per_page' => '9', 'order' ...
1 vote
0 answers
28 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
59 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
24 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
51 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
28 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
37 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 &...
  • 1
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
36 views

How to merge the content of posts that have the same title?

Good evening everyone... I apologize in advance for my bad English, for any complaints go to google translate :). I need to merge posts with the same title and I don't know how to do it. The situation ...
0 votes
0 answers
10 views

Different post slug based on archive

I need some help with my current WordPress site. The site got 6 post categories. Posts can have multiple of these categories. The slug of the posts include the category slug. For each of the ...
  • 1
0 votes
0 answers
39 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
43 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
218 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
58 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
51 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
80 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
23 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
66 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
50 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
3 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
137 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 ...
0 votes
1 answer
77 views

Show posts from two specific category in WP_Query

I've two category employee and full-time. If a post publish in both (employee and full-time) category then the post will show in his specific section. If post has only employee category, not full-time ...
's user avatar
0 votes
1 answer
223 views

Filling custom post type posts from a rest api

I have been trying different wordpress intermediate challenges, I came across one today that brought up a question I had no idea how to resolve it requires displaying data from a rest api however the ...
  • 101
0 votes
1 answer
75 views

How to query for all posts that have a particular meta key?

I have many posts. Some have meta data, with a key called "foo". How can I query for just the posts with the meta data "foo"? metadata_exists requires the post ID, I'm trying to ...
  • 465
0 votes
2 answers
109 views

How to check in functions.php if there is data in a WP_Query?

I have 2 different WP Query on the home page. I need to check $home_query condition in functions.php then I want to do something if $home_query returns null. I tried with pre_get_posts action I couldn'...
  • 3
0 votes
1 answer
96 views

Shortcode with 'year' parameter

I would like to display posts with a 'year' parameter. For example: to display posts from 2020, the shortcode should look like [archived-posts year="2020"]. I have tried my code below but it'...
  • 129
0 votes
1 answer
21 views

How do widgets access posts they should display?

How do widgets embedded in a page access posts they should display? How do widgets (php code) in the page access the posts they should display (via the used template's post loop / with wp_query and ...
0 votes
1 answer
25 views

Does Wordpress run a post query when a page is invoked?

Let's say I create a what in the Wordpress backend is called a page (pages - new page). I put some arbitrary page elements on it (e.g. title, text, some images, a widget or two displaying posts from ...
0 votes
1 answer
131 views

How does post loop integrate individual page elements

I am just trying to understand how coding in Wordpress works. I have read a bunch of tutorials about post loops and how to modify them with queries, but I have no idea how individual page content I ...

1
2 3 4 5
25