How do I pull the 4 most recent or most visited posts on the wordpress ?
How do I pull the 4 most recent or most visited posts on the wordpress ?
To search for the latest posts you can use the wp_get_recent_posts
function, this function accepts as the first parameter an array and as second parameter "how do you want the result", but I believe the configuration below is enough 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's a good idea to use some plugins like popular wordpress posts , but there are several others that you can find searching on Google by
get popular posts wordpress