How to pull the 4 most recent or visited wordpress posts

Asked

Viewed 339 times

1

How do I pull the 4 most recently or most visited posts on ?

1 answer

2

To find the most recent posts you can use the function wp_get_recent_posts, this function accepts as first parameter an array and as second parameter "how you want the result", but I believe that the configuration below is sufficient for you.

$args = [
    'numberposts' => 4
];

$recent_posts = wp_get_recent_posts( $args, ARRAY_A );

other parameters that can be used are:

'offset' => 0,
'category' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' =>'',
'post_type' => 'post',
'post_status' => 'draft, publish, future, pending, private',
'suppress_filters' => true

For most popular posts I think it is ideal to use a plugin like wordpress popular posts, but there are several others that you can find google for

get popular posts wordpress

Browser other questions tagged

You are not signed in. Login or sign up in order to post.