Questions tagged [get-posts]
get_posts() is a function for creating multiple loops. It retrieves a list of latest posts or posts matching criteria.
806 questions
0
votes
1
answer
43
views
How Do I Remove Pagination From A Single Blog Entry?
I am using the Pipdig theme Opulence, and am currently using a Static Front Page for a custom homepage, and a separate Static Posts page, so that I can decide where my viewers go.
I have also made it ...
1
vote
2
answers
18
views
Category Attachment Pagination 404 Error on 2nd Page
I'm customizing category.php to display all attachments with a specific category, but when I click on a link for a page besides the first one, I get a 404 error. To reproduce:
Install a new Wordpress ...
2
votes
1
answer
112
views
Equivalent of url_to_postid() for non-post URLs?
If I do url_to_postid("https://example.com/2024/05/test") I get back an int which I can then pass to get_post(). That works perfectly.
But what if I request a tag or a year? What's the ...
0
votes
0
answers
44
views
get_posts() return NULL using a custom plugin and add_submenu_page() with Post Type
Inside a custom plugin and using add_submenu_page() for custom post type I want to display one post.
As the other post_type I use get_posts($the_id, $arr_params) to get information about it, except in ...
1
vote
1
answer
53
views
How to compare Event period with Week period using get_posts(), meta_query, relation and compare
I have many posts, each post is an event with a period .
This period can be 3 hours, 3 days, 15 days, 3 month.
I defined the start time of event with start_timestampevents and the end with ...
0
votes
1
answer
33
views
Wordpress duplicating posts from single loop
I've created a custom post type with ACF custom fields included. The CPT is being placed inside of a bootstrap slider. Everything seems to be working, except, the posts being rendered on the page are ...
0
votes
1
answer
14
views
How can I guide user to the next unread post within category
I am struggling with a coding problem as we want to guide the user to the next unread post within a category ('puzzles'), since we don't want users to go back and re-submit old puzzles to game their ...
0
votes
1
answer
106
views
Operator 'AND' in the get_posts() function's tax_query terms not working
I am trying to get posts that are present in both the taxonomy terms. This is the code that didn't work:
$args = array(
'post_type' => 'workshops',
'posts_per_page' => -1,
'fields' =...
0
votes
1
answer
86
views
get_posts() function does not honor correct post type
I'm fetching all posts of a specific custom post type like below.
print_r(ANCR_POST_TYPE);
$announcements = array();
$announcement_posts = get_posts(array(
'post_type' => ANCR_POST_TYPE, // ...
1
vote
0
answers
24
views
post__in select all custom posts and not the selected array of ids
In order to add a personilized sidebar for costom posts I define a shortcode using add_shortcode ( >name shortcode< ) and I recall the shortcode in sidebar using a plugin.
In the sidebar I must ...
0
votes
1
answer
238
views
How to cache wordpress get_posts query using transients?
I have a website with over 100,000 posts. On a term taxonomy page, the main query WP_Query->get_posts() is the slowest. I want to cache the results of this query using transients-api. I tried ...
0
votes
1
answer
187
views
Sort by multiple columns using get_posts
I have the following:
get_posts(array(
'post_type' => 'event',
'posts_per_page' => -1,
'meta_key' => 'start_date',
'orderby' => '...
0
votes
1
answer
125
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" ...
3
votes
1
answer
440
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 ...
0
votes
1
answer
76
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
219
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 ...
1
vote
0
answers
31
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
158
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
128
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
273
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
57
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
205
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
161
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 ...
0
votes
1
answer
715
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
176
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
37
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
240
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
233
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
2k
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-...
0
votes
1
answer
147
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('...
0
votes
1
answer
54
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
140
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
149
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 ($...
0
votes
1
answer
859
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 ...
1
vote
1
answer
743
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',
'...
0
votes
0
answers
171
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
66
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
136
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
275
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
0
answers
144
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
1
answer
660
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
1
answer
1k
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
54
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
1k
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
1
answer
25
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
210
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
308
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
1
answer
295
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
1
answer
603
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
53
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 ...