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
1answer
9 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
20 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
23 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
23 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
17 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
47 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
59 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
11 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
9 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
41 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
23 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
20 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
38 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' ...
0
votes
0answers
28 views

Supless_filter / Wp_query / get_posts / Elementor button / Loop / geotargeting

I have the following problem Got geotargeting and custom post type (Jetengine) I then inserted everything into Elementor that I have a list with the posts with a "Load more" button (where a ...
0
votes
0answers
13 views

“Post List” Loop containing other “Child Post List” loops causes pagination error ELEMENTOR

I am using a loop template to display posts in a custom template. The loop template contains another loop to display a list child posts. Child post list requires paginaion, but I am encountering a bug ...
2
votes
1answer
34 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
54 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
26 views

Sort custom endpoint API by number of views

I have registered a rest field in my functions.php for the API to show: register_rest_field( 'post', 'views', array( 'get_callback' => function ( $data ) { return get_post_meta( $data['id'], '...
0
votes
0answers
39 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
0answers
14 views

Prevent duplicate posts in categories

I would like to exclude from the "Load More" button or "Scroll infinity" posts already previously displayed on the current page. I use a post blocks which contains various ...
0
votes
0answers
16 views

Display only one category under a custom post in WordPress

I am willing to display only one category so that I call the very exact album's song and am not achieving it no matter what. Would appreciate some help since the developer is not responding. Thanks! I ...
0
votes
0answers
13 views

Post ID into plugin

I have a small plugin to update the acf fields in a posts. In each post, there are many fields that need to be updated with the received data from the API. In the code below, I first demonstrate from ...
0
votes
0answers
176 views

WPGraphQL array of posts query

Been trying to figure out how to use WPGraphQL to do anything more than trivial strings for some time the documentation is awful for everything besides the basic functionality. I have a 'Related Posts'...
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
35 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
34 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
142 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
159 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
662 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
0answers
7 views

Filters post by subcategory slug using buttons

I load in subpage post with one category now i try filter this post by him subcategory and get link to page some like mypage.com/subpage/?slug=fish after click button and see only fish post. I should ...
0
votes
1answer
39 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
69 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
0answers
21 views

query_posts in pre_get_posts removes all body classes - how can I reset or keep them?

I've created a function that searches images for a tag, uses them to create a loop and build an array of their parents' IDs. Its in a pre_get_posts. Its all working fine except I'm obviously ...
0
votes
1answer
19 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 ...
0
votes
1answer
100 views

Post Filtering by GET URL parameters

I am trying to add a simple filter for posts in my wordpress site by setting parameters in the URL, however it is simply not filtering the posts which is driving me crazy. All the tutorials or forums ...
0
votes
3answers
44 views

Sorting not working with get_posts

I have been looking at this for hours but can't get it to work. $newsItems2 = get_posts([ "post_type" => "post", "post_status" => "...
0
votes
0answers
9 views

Question: How can I retrieve the post details liked by the current_user using the post_id from the “Different” post_type?

I am soo new to Wordpress development, so I am so lost in this. I have a custom post type "Like" that automatically adds the post_id of the page/post the user liked, and the "Like" post type contains ...
0
votes
1answer
37 views

How to change category id on get_posts array

I am making a carousel for my AMP page, and I want to re-use the code, so I made it into a template, however, I am having the problem with changing ID on the array for category value, I would like to ...
0
votes
1answer
25 views

Drop down filter sort posts by latest, last 7 days and monthly

I am trying to use a drop down for users to select and show posts made latest, last 7 days and monthly. Currently I was able to find code to just sort by date in ASC and DESC order. <div id="...
0
votes
0answers
74 views

How do i POST to WordPress rest API from the same domain?

I created a custom rest API route - > http://mydomain/wp-json/v1/wp/custom/user now this POST request to this route works perfectly from a remote host. Some things change in my dev env and the JS ...
0
votes
1answer
183 views

How to get an array of pages ID by some page's slug and all its children pages in get_posts() function?

I have a custom function in my theme that creates a dynamic sitemap.xml file. For that I'm using $myVar = get_posts( array(...) ). In that array I need to exclude some pages. I want to exclude some ...
0
votes
0answers
228 views

how to get posts from dynamic category with wpbakery page builder post grid

I use Zephyer theme and I created a custom content template and I want to show posts from a dynamic category name . In default settings of wpbakery page builder post grid I can't set dynamic value ...
1
vote
0answers
46 views

A smarter way to display multiple loops inside a page template

I'm trying to make a page with multiple loops. I need each loop to display posts from a particular category. One category after another. At the moment I have the loop below displaying posts from a ...
0
votes
0answers
9 views

I want to get the data from WP-posts according to the Post_modified date. Please check my code and help me out

$args = array( 'post_status' => 'publish', 'post_type' => 'therapist', 'post_parent' => 0, array( 'meta_key' => 'post_modified', ...
0
votes
0answers
13 views

Wrap to First/Last when Linking to Previous/Next Post

I am trying to display two links, previous and next post in the current category. What I have so far works fine, but how do I make the next link to the first post when on the last post and vice-versa,...
0
votes
1answer
102 views

get_posts() not working with multiple statuses

I am running the following code: $posts = get_posts([ 'post_type' => ['my-type', 'another-type'], 'numberposts' => -1, 'order' => 'ASC', 'orderby' => 'title', ...
1
vote
1answer
51 views

How do I see the mysql query generated by get_posts( $args )?

I'm trying to use get_posts( $args ) to get some custom post types. Is there a way to see the mysql query generated by the get_posts function?

1
2 3 4 5
16