Questions tagged [get-posts]

get_posts() is a function for creating multiple loops. It retrieves a list of latest posts or posts matching criteria.

Filter by
Sorted by
Tagged with
0 votes
0 answers
10 views

How can I show a field ID in Elementor with Request Parameter

I have a ID Field called name and I need get this field in Elementor. I don´t know if it show as get, post or queryvar. Please, I need help Maybe with add_action( 'elementor/query/nameid', function( $...
0 votes
1 answer
23 views

Link on post title only if post have content

Hello i create an archive.php custom for category-id (category-id.php) and use this code <?php /** * A Simple Category Template */ get_header(); ?> <section id="primary" ...
0 votes
0 answers
18 views

how should i get products based on tags in woocommerce

i want to write a shortcode to get or filter products by tags. for example, i want to get all products that have both 'male' and 'sport' tags. i don't want to separately find product that have 'male' ...
3 votes
1 answer
50 views

A better way of getting draft posts that has a particular post meta using get_posts function

I'm developing a simple WordPress plugin as part of my WordPress learning. It's about bulk post approval. The full plugin code is given in this question: Bulk post approval and publishing doesn't ...
  • 166
0 votes
0 answers
20 views

Create a hierarchical list of posts that's grouped and nested by category

I'm trying to show a list of book recommendations, grouped and sorted by category. The problem is some book recommendations belong only to a top-level category and some belong to sub-categories. I'd ...
  • 1
0 votes
1 answer
34 views

filter on get_posts efficiently

I have posts with the following categories: A category that is a year(2017,2018...2022), a category that is type:(worldwide,Europe, local) I am trying to give users in the frontend advanced search ...
0 votes
0 answers
22 views

How to I add count of custom posts listed in a post as a prefix to its title

I run an affiliate site that consists primarily of posts that list product ideas (x products for purpose Z). Each post is a standard post with a custom field ID that is used to generate the list of ...
0 votes
0 answers
21 views

NewsPaper WP Theme - Additional Related Posts Filter by Time (divTag composer)

I have specific situation here and really need help from someone who has experience with NewsPaper theme and tagDiv composer as well. I want to add new function (or alter current, nevermind) that will ...
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
0 answers
15 views

How to replecate the _fields parameter in custom REST api endpoint

I am trying to bring in additional fields like I can in the wp/v2 namespace using the posts endpoint. How do I replecate the _fields property to get the wp:terms and whatnot for access to the featured ...
0 votes
0 answers
9 views

How to retrieve _embed (etc) fields in get_posts custom query?

I am making two custom REST endpoints that grab posts by category and tag slug instead of id for linking purposes, and I can't seem to access any of the _embed fields to get access to wp:term for ...
1 vote
0 answers
25 views

Add Category names to post lists of custom post type

im beginner at codes, I have some code to show posts of "Custom Post Type" and it's working and it shows post titles, I want to add a category name to it too. " I tried <?php echo ...
0 votes
0 answers
142 views

WordPress extremely slow when using get_posts with multiple meta_query relations

I am having an issue with this query. Do I have it written incorrectly? This is on WP 6.0.2 and PHP 7.4.30. $now = current_time( 'Y-m-d H:i:s' ); // Fetch all upcoming bookings and events. $posts = ...
  • 43
0 votes
0 answers
37 views

Empty query on Custom Post Type, using WP_Query or get_posts

I've searched in SE and on Internet for 2 days without success. The problem is: I've a function that runs on "save_post_eventi" hook in WP backend dashboard, that starts with a simple query: ...
0 votes
1 answer
43 views

How to get permalink of post based on post name?

Hi I want post permalink like events/post-name not events/?post_type=45 I am using get_permalink(20).
0 votes
2 answers
16 views

Install wordpress and replace database (from previous site)

Hi I had a WordPress installed on a shared hosting server. somehow the entire folder gets deleted and hosting provider cant help with this. I only have backup of the theme. Now I managed to recover ...
0 votes
0 answers
38 views

How to return a specific attribute

The following returns the description return (new CSimpleField('product','data','description',null,null))->GetHtml(); I am trying to return a specific attribute named pa_color but it is not ...
  • 101
0 votes
0 answers
41 views

How to add content above footer in posts from specific category

I want to add “custom footer” above default footer to posts for specific category I have function that works, but that "custom footer" also appears on the archive category pages which I don’...
0 votes
0 answers
80 views

How to save HTML data into SQL post_content column

I have a custom template file containing some HTML tags and get_post_meta function. I want to insert the HTML data into post_content column. Is there a wordpress function or SQL function to save into ...
0 votes
1 answer
101 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
0 votes
1 answer
86 views

How to Get Posts, Including Private Ones?

Currently in one of my php files, I retrieve all of the public posts like this: $posts = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'post' )); However, this only returns ...
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. <?...
1 vote
1 answer
27 views

Better way to list links with different meta values using same meta key?

This works, but I will need it to make 8 different lists on the page, using same meta key but 8 different meta values. Is there a more efficient way to achieve this rather than repeating the same code ...
0 votes
0 answers
97 views

How to add date_query to meta_query array

I am building a meta query array and all fields for the user are optional so some might not have any data. But there is also an option which requires a date query. I am still checking to see if this ...
0 votes
1 answer
57 views

date_query empty results with custom post type

I am trying to use get_posts to return data between certain dates but I always get an empty result even though there is a lot of data. This is for a custom post type. $args = array( 'post_type'...
0 votes
1 answer
727 views

How to get woocommerce orders with get_posts method in a shortcode

I'm writing shortcode which must show all orders placed by current user. I followed this two guidee to get them: https://www.businessbloomer.com/woocommerce-easily-get-product-info-title-sku-desc-...
  • 101
0 votes
1 answer
47 views

Why my query is not "Main_query"?

I made a new page in admin panel like this. I want my Query here to be main_query so the other plugins could hook it, modify limits, etc... add_action('admin_menu', function (){ add_submenu_page('...
  • 101
0 votes
1 answer
31 views

How to get a random single category name in get_posts()?

How can I get a random category name one at a time?? The post may have multiple category instead of a single category. I just want to show a single category name in the post grid loop. $...
user avatar
0 votes
0 answers
44 views

Orderby meta_key/meta_value not displaying anything, am I overlooking anything?

I have an issue with my orderby using get_posts(). I want to order in alphabetical order a list by city name using a custom meta field, but it comes back empty. However when I orderby title, the list ...
0 votes
0 answers
86 views

get value from get_post_meta then reuse it in another get_post_meta

I am writing the following code, which I have updated since the original question so as to give the entire picture. I am a newbie, and the reason why I am not using the get_posts() function in ...
0 votes
2 answers
90 views

Iterate over get_post_meta() result

I have WordPress code like below. function get_preselect_values() { $volunteers = get_post_meta($_POST['element_id'], "volunteers", false); $users = array(); foreach ($...
  • 407
0 votes
1 answer
284 views

How to use get_posts to filter against a single post id?

How do I use get_posts to filter against a single post id? (I don't want to use get_post because am using this in another function that could take other parameters and should return an array). The ...
  • 119
1 vote
1 answer
307 views

Get posts for which a custom field is not present, with get_posts

I'd like to get all posts for which the custom field hidden is NOT present. This does not work: $postsForSitemap = get_posts(array( 'numberposts' => -1, 'orderby' => 'modified', '...
  • 87
0 votes
0 answers
118 views

get_posts() returns empty on custom post type /wp-admin/edit.php

I need to do a get_posts() to fetch a list of "product" type posts, but when I do it on edit.php?post_type=mycustompost it returns empty. If I just simply do the same function but on edit....
0 votes
0 answers
62 views

How to add first 3-4 post tags on WordPress Post Title

Is there any theme function code that put the first 3-4 post tags on WordPress Post Title. Let's assume I am creating a new article for my site and I added the below tags for my post My Post Title - ...
0 votes
0 answers
70 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
1 answer
95 views

get_posts query is taking about 40 seconds to execute

I have a meta query in get_posts that's taking a ridiculously long time to complete. It works fine, but it just takes way too long. I have a custom post type named event. On every event post, there is ...
  • 287
1 vote
0 answers
127 views

Order posts by custom field DATE value

Hello I need to order posts by custom field date value, so for example:2022, 2021,2020 <?php // get posts $posts = get_posts(array( 'post_type' => 'events', 'post_status'=> '...
  • 11
0 votes
1 answer
334 views

Order custom post type by custom field (created by PODS) via PHP

I have this PHP code: $posts = get_posts([ 'post_type' => 'clen', 'post_status' => 'publish', 'numberposts' => -1, 'orderby' => 'funkcia', 'order' => '...
  • 111
0 votes
1 answer
540 views

View post with specific category id and name which I selected in the backend (drop-down option)

I'm trying to get the category ID from Kirki Function and then pass the ID into a loop to get View all posts from that specific category id with name. I write this code at the backend: Kirki::...
0 votes
1 answer
48 views

I'm having trouble with Related Product "tax_query" 'terms' value

I have two custom page types. the first is "product" and the second is "accessories". On the product page, there is the accessories category "inputs" raleted post. Inputs ...
0 votes
1 answer
679 views

Wordpress block editor embeds not working in theme (single.php)

I am trying to embed 'spotify' and 'youtube' services in the block editor. When added from the admin, they are displayed fine in the block editor, but when the post content is printed from the theme (...
  • 225
0 votes
1 answer
22 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
148 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 ...
0 votes
2 answers
163 views

how to load random related posts with specific custom fields?

I want to load 3 posts that have the same custom field value as the current post. for example: The current post has 3 custom fields: color: black background: red lastname: doe Now I want to load ...
  • 167
0 votes
1 answer
124 views

Is it possible to query posts with tax queries after multisite switch_to_blog() function?

On my newly installed multisite with 1 installed plugin ACF. And all code below is not being run though any filter or action and on the front end. On the front end in the page.php template, I can ...
  • 447
0 votes
1 answer
347 views

How I can change the condition or compare operator for WP_Query in pre_get_posts

So here is my problem I want to show Posts if have same category if not have post then show post of same tag. And to do that I am using "pre_get_posts" action. and setting query like ...
0 votes
1 answer
47 views

Recent posts on homepage: different thumbnail based on logged in status and post category

This works well on archive.php, but not working on the homepage. For some reason, the first statement doesn't get applied: if a post is in Members category and user is not logged in, it's supposed to ...
0 votes
1 answer
485 views

Populate select list with meta values from all posts of a Custom Post Type

I've got a CPT of Inventory and I'm trying to show a dropdown of all Mfrs. I've got the form and pre_get_posts function so that when a user selects a Mfr, the page refreshes and shows only the ...
  • 215
0 votes
1 answer
2k views

WP get_posts meta_query using ACF repeater field

I have a Custom Post Type of 'ITEM' that allows the admin to add an 'Item Number' using an ACF text field. In another Custom Post Type of 'GROUP' the admin can use an ACF Repeater to enter multiple '...
  • 215

1
2 3 4 5
17