I’m trying to get only the fields that I need using the get_posts()
function in WordPress. I currently have the following code:
$posts_args = array(
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 5,
'fields' => 'ids'
);
$post_ids_r = get_posts($posts_args);
This works fine if I only want to get the id. But if I want to get the permalink or the title of the post along with the ids that’s where I’m not sure what to do. I already tried the following:
'fields' => array('ids', 'post_titles')
'fields' => 'ids,post_titles'
'fields' => 'ids,titles'
'fields' => array('ids','titles')
But nothing works, I guess the only one that it recognizes is the ids
field. Is there any other way to do this if its really not possible to do it using get_posts()
? Thanks in advance.