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
0answers
15 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
22 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
8 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
14 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
11 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
11 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
17 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
18 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
33 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
60 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
26 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
15 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
63 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
29 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
64 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
18 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
10 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
18 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
32 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
8 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
19 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
15 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
31 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
64 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
67 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
23 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
31 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
25 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?
0
votes
0answers
20 views

How to get post from all custom post_type multisite to the main site with pagination ordered by date?

Currently this is my WordPress Multisite: Main site -Sub Site -Sub Site -Sub Site -Sub Site and this is the example code for getting all post from multisite : foreach( $blog_ids as $id ) { ...
0
votes
0answers
13 views

Get all posts by many custom post types

Question: I have many custom post types and i want to return all the posts by just a few of the post types: For example i have an array and was wondering if there was a way of passing this array to ...
0
votes
2answers
115 views

Recoverable Fatal Error - Object of class WP_Post could not be converted to string

Im using ACF and trying to show a post type title based on the current time. So I have my post type entry with start_time and end_time and my conditional is showing my div.onAir, but Im getting this ...
1
vote
0answers
18 views

How do I exclude recent post from recent post php widget

I have this code, and I tried adding in post__not_in as suggested by another post I found on this website, and it didn't break anything but didn't work either. I also tried different examples. Here's ...
1
vote
1answer
99 views

add active class based on permalink and url

i am facing a issue, on my wordpress site in left side i loaded post list with title and excerpt, and when you click on that content will get load on right side of page and its working fine but i ...
1
vote
0answers
17 views

Create a new query in function.php to filter blog posts

My goal is to filter blog posts (those which are requested in the blog page - Reading settings) depending on an expiration date, and then to change their category depending on a choosen future ...
0
votes
1answer
43 views

get_the_category return empty inside loop

I'm creating a custom template for my website and I'm currently using this code in order to loop to my multisite worpress and get the latest posts: global $post; global $wp_query; $subsites = ...
0
votes
1answer
36 views

Foreach Loop Of Post Types With Nested If Else If Not Completing Process

When my plugin is updated I am trying to write new values to the database. I am running through the post types and if it is Page Product or Post I want to place INDEX in to the DB. Else I want to ...
0
votes
1answer
69 views

Get latest posts from multisite

I've created a multisite on a local VM and installed my theme. Now I'm trying to get the latest posts from all the sites in order to display them ordered by last updated on homepage. From what I've ...
0
votes
1answer
84 views

get_posts return only first result

I try to get_posts like this: $sql = $wpdb->get_results( $querystrShop ); // Create array of product ID foreach ($sql as $prd) ...
0
votes
1answer
20 views

Modify default Related Posts Code to Custom Post Type

I'd like to modify this basic related posts code to my custom post type "Videos". Since I'm new to this stuff, can someone help me understand what I need to modify in this code so that it pull related ...
0
votes
1answer
87 views

get_posts( $args ) return empty data

I'm writing plugin for syncing prices of WooCommerce products with external source. So I want to get products with EAN (have meta data _wpm_gtin_code). Whaterver I pass to get_posts($args) I get empty ...
3
votes
3answers
126 views

Query posts ordering by title, but ignore " and special characters

I use following function to get my custom posts ordering by title $posts = get_posts( array( "orderby"=> "title", "order" => "ASC", "post_type" => "my-custom-post-...
0
votes
0answers
46 views

Related posts queries

Hey so I'm building a section that shows the related articles of a blog posts by doing a query with the post tags. I thought this section was working but suddently it started showing 5 posts instead ...
0
votes
1answer
86 views

How to Loop Through all Posts and Count Attachments using Get Media Attachments

I am working, on a code, where i need to loop Through all posts of a given author, and then for each post of that author, count the number of media attachments, the post has and then echo it. I am ...
1
vote
0answers
24 views

Weird orderby => post__in issue

I seem to have run into a sort of odd issue with WP_Query post__in I can't quite figure out. ANY help is appreciated! Goal/Progress so far: Overall I want to merge two arrays and use the merged ...
0
votes
1answer
18 views

Look up all posts by status or meta value - performance difference

Anyone know if there is likely a big performance difference to these two queries? get all posts by status = TRASH get all posts which have the meta key _delete_product and has a value of TRUE I will ...
0
votes
1answer
19 views

Return number of all custom posts type by author in all statuses

I'm using the code below to try to get a proper post count of all posts by a user but it's returning 0 for each user. function get_user_posts_count($user_id, $post_type) { $args['author'] = $...

1
2 3 4 5
16