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
1 answer
17 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
15 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
11 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
34 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
29 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
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
0 votes
1 answer
27 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
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. <?...
1 vote
1 answer
25 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
39 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
36 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
218 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
43 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('...
  • 1
0 votes
1 answer
25 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. $...
0 votes
0 answers
41 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
32 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
0 answers
20 views

How to show multiple posts thumbnail, title and date in widget

I`m making a plugin with a widget to show a post that I recommend or mark with a checkbox in the post list. Question: I have said in the code that I want to show 2 post per page. It only show one with ...
  • 21
0 votes
0 answers
8 views

I need to create "View Profile" and "Edit Profile" links by incorporating the Post Title/ID, but can't seem to manage it

I'm currently building a new site, using a front-end user form for members to go in and edit their own details, with an Administration-only front-end dashboard. Using plugin buttons I've already ...
0 votes
0 answers
14 views

Show only posts with titles/permalinks that do not contain certain words

I want to show only posts with titles/permalinks that do not contain certain words, for example, the word "how-to". it is possible to do that and how? This is my current code to show all ...
  • 101
0 votes
2 answers
54 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 ($...
  • 397
0 votes
1 answer
81 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
150 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
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
72 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
61 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
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
1 answer
62 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 ...
  • 277
1 vote
0 answers
118 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
231 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
0 answers
25 views

Get_post_custom not fetching value from array wordpress

I am trying to fetch values of 'email' from an array, This code is showing complete array: global $post; $post = $wp_query->post; $id = $post->ID; $custom_fields = get_post_custom($id); ...
  • 1
0 votes
1 answer
343 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
43 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
509 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 (...
  • 213
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
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 ...
0 votes
2 answers
112 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 ...
  • 147
0 votes
1 answer
94 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
251 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
45 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
368 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
1k 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
0 votes
1 answer
33 views

Custom post type data not displaying If I select the category from the dropdonw

I have created a custom post type. I am able to add all the details and it's working. I have a dropdown and I am getting my category in that dropdown. Once the user selects the category from the ...
0 votes
1 answer
325 views

Why set cookie from URL parameter doesnt work all the time?

I use only "pages" from my WP installation (not posts) and I want to set a cookie based on the existence of a GET parameter in the URL. I have put the following code in the top of my page....
  • 1
0 votes
0 answers
62 views

AJAX - get_posts for a specific post type returns empty

I'm trying to load more posts via an ajax call but the array always returns empty. To troubleshoot, I replaced the "testimonial" in "get_posts" with "post" and "...
  • 1
0 votes
1 answer
566 views

Form checkbox value going to dynamic URL

Well, I have a Database made mostly with 'Advanced Custom Fields' in a page on my site that is supposed to get all the STORES (custom post type) of a city and show them to me, and by changing ...
1 vote
1 answer
196 views

var_dump and print_r cause white screen

My template is very simple: get_header(); $new_p = get_posts(array('post_type' => 'post', 'numberposts' => 6)); get_footer(); whenever I put var_dump($new_p); or print_r($new_p); below $new_p = ...
  • 83
1 vote
1 answer
66 views

Show Only Posts Owned By Logged In User + my post

I would like to restrict access for logged in users to specific posts: their own posts and my posts (as they will serve as templates for them). I find this code snippet that works perfectly to show ...
  • 11
-1 votes
1 answer
50 views

get_posts shows current post, not defined posts with args

I want to show defined posts but get_posts shows current post without use definition in args.Why, how to solve it? what is difference between get_posts and wp query? thanks add_action( '...
0 votes
0 answers
255 views

get_posts filter meta_query using ACF Checkbox

I have a checkbox field for a custom_post_type called distributors. I am using get_posts and meta_query to filter the posts by the region checked. Each post has a value of canada or usa. In my code I ...
  • 307
1 vote
1 answer
37 views

Ordering posts in get_posts

I am having a custom block which uses the following code to fetch a list of comma separated posts. $numberposts = "7,9,5,10"; $post_ids = explode( ',', $numberposts ); $args = ...
  • 31

1
2 3 4 5
16