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
1
vote
1answer
49 views
+50

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', '...
0
votes
0answers
20 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
0answers
23 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
0answers
56 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
0answers
23 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
1answer
45 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 ...
1
vote
0answers
31 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'=> '...
0
votes
1answer
19 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' => '...
0
votes
0answers
17 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); ...
0
votes
0answers
20 views

get posts, run a custom query, and join the results

I need to get the posts, and then run a custom query (getting posts too, but joined table with several custom tables, to modify the posts sql where is not useful here) and return an array with the ...
0
votes
1answer
23 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
0answers
32 views

metabox upload multiple file

I have upload multiple file metabox, my problem is I need to display all files links attached to this post inside the post editor. when i upload the files it is already saved under the media but the ...
0
votes
1answer
33 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
0answers
9 views

Get posts on template redirect

I'm trying to validate some $_GET parameters before letting the user view a particular page. In the actual template file, this code works: $user = get_user_by('ID', $_GET['sscp']); $args = [ '...
0
votes
1answer
118 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 (...
0
votes
1answer
19 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
0answers
16 views

limit displayed posts to only one author by id

I have a specific need to display the posts filtered by author. Let's say I have the author with id=4. I want to create one page, where only his posts are listed, with sidebar categories selector. On ...
0
votes
1answer
38 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
2answers
54 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 ...
0
votes
1answer
70 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 ...
0
votes
1answer
54 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
1answer
41 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
1answer
152 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 ...
0
votes
1answer
484 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 '...
0
votes
1answer
24 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
1answer
111 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....
0
votes
0answers
28 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 "...
0
votes
1answer
328 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
1answer
101 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 = ...
1
vote
1answer
17 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 ...
0
votes
0answers
21 views

Display post count per week per category

I'm looking to create a page that shows a list of all categories that have posts within the current week, with a number next to the name of the category that is how many posts in it for this week. I ...
-1
votes
1answer
43 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
0answers
85 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 ...
1
vote
1answer
28 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 = ...
0
votes
0answers
11 views

Random GET value on Adress Bar [duplicate]

While working on websites that involve WooCommerce I keep on having random GET value generated on the address bar. For example, I recently added an E-Commerce using WooCommerce plugin to this site, ...
0
votes
0answers
39 views

building filtering system

I have a custom 'pre_get_posts' function, that attaches meta_query: function my_pre_get_posts($query) { $query_filters = array( 'color' => 'color', 'size' => 'size', 'type' ...
2
votes
1answer
37 views

Show post only if match all categories

I have posts that have multiple different categories including a common category called "Videos", now I'm trying to show only posts that match with the all categories of the main post ...
0
votes
0answers
70 views

How can I get posts by 2 meta keys, prioritising one of them?

Background: On my site, each product's post has two sets of the same features. One is set by a program that imports products, the other is set by admin. The features can be price, weight, brand, a ...
0
votes
0answers
96 views

custom post type get_posts() function not work

$orders = get_posts(array( 'post_type' => 'lp_order', )); foreach ($orders as $order) { // get all order data code } This the code I will try to learnpress plugin order post type front end ...
0
votes
1answer
21 views

php loop error for count posts in category

I have multiple categories on my wordpress page and each of the categories has 1 to n subcategories. If a subcategory contains only 1 single post I would love to display an excerpt of this post, ...
1
vote
2answers
84 views

Creating query to show which editor (classic or block) was last used to edit a post/page

I have a WordPress site that has some pages created/edited in Classic Editor, and some pages that built/edited with Gutenberg/Block Editor. I am trying to create a report of which pages use each ...
0
votes
1answer
35 views

get_posts wont produce a list of custom type from a given category [duplicate]

Hi, I created a custom post type called "news" and custom categories called "news_category" to have them categorized. I want to list "news" posts that belong to one of ...
-1
votes
2answers
195 views

Weird query with get_posts and WP_Query

Attempting to make a search in a custom post type "comunicados" inside a shortcode in a custom plugin I send this to get_posts() Array ( [posts_per_page] => -1 [post_type] => ...
0
votes
0answers
25 views

Cant list custom type posts based on category [duplicate]

Hi, I want to list posts which belong to custom type "news" under a certain category. This is my code: <?php $news = get_posts( array( 'post_type' => 'news', 'category' =&...
0
votes
1answer
302 views

get_posts() SQL Injection

I'm working on a custom search page and I usually use wpdb->prepare when crafting custom queries. But this time I went with get_posts to create the below query. But I'm wondering if I have to worry ...
0
votes
2answers
16 views

How to Link to Most Recent Custom Post of Same Term

Title says it all. I'm trying to link to the most recent post of a custom post type, but only within the same term. Currently my code successfully echos the correct term ID but doesn't show a link ...
0
votes
2answers
2k views

How to get posts that contain multiple terms from multiple taxonomies?

If I have a list of term ids, like 1,2,3,4,5 that correspond to tags, categories and custom taxonomies, how can I get all the posts that contain all these terms? Let's say from that list of term ids, ...
0
votes
1answer
134 views

How to get a custom post with the largest ID (not the last post by date)

I would like to get the (one) post with the last ID, even if it is not the last post by date. The post belongs to a custom post type. I need this to assign custom id numbers to my orders. When ...
0
votes
0answers
74 views

Limiting the Number of User Posts to Their Own Posts

I have set users to only see their own posts. But the total number of articles is still visible. Can we limit it to its own number of articles? How can it be done without plugins? related picture here:...
0
votes
1answer
27 views

how to hide all posts under one category

Suppose I have a lot of posts under notices category. When I click on notices, it will display all posts one after another under the notices.Instead of displaying one post after another, how to hide ...

1
2 3 4 5
16