pvc_get_post_views()
Description
Gets total post views for a post or array of posts. The function is located in the functions.php file of the plugin.
Usage
pvc_get_post_views( $post_id = 0 );
Parameters
- $post_id | int / array: Post ID or array of post ID’s
Return
The function returns the sum of the post views after casting into an int type.
pvc_post_views()
Description
Displays a post’s total post views along with the label and/or icon. The function gathers all of the data, prepares the display, and then displays the total post views counter. The function is located in the functions.php file of the plugin.
Usage
pvc_post_views( $post_id = 0, $echo = true );
Parameters
- $post_id | int: Stores the post’s ID.
- $echo | boolean: Determines whether the post views should be displayed or not.
Return
A string of display options that include the post’s ID, total number of views, label, and icon.
pvc_get_most_viewed_posts()
Description
Gets the most viewed posts ordered by views count. This function is a wrapper for get_posts() and it accepts all the get_posts() parameters. The function is located in the functions.php file of the plugin.
Usage
pvc_get_most_viewed_posts( $args = array() );
Parameters
- $args | array: Array of optional arguments
Return
Array of most viewed posts stored in the array of post objects.
Example
Getting events ordered by post views in ascending order.
$args = array( 'order' => 'asc', 'post_type' => 'event' ); $most_viewed = pvc_get_most_viewed_posts( $args );
Or same as above using get_posts() function.
$args = array( 'order' => 'asc', 'post_type' => 'event', // required by PVC 'suppress_filters' => false, 'orderby' => 'post_views', 'fields' => '' ); $most_viewed = get_posts( $args );
pvc_most_viewed_posts()
Description
Displays a list of the most viewed posts. The function declares an array of default $args parameters.
Default parameters
$args = array( 'number_of_posts' => 5, 'post_type' => array( 'post' ), 'order' => 'desc', 'thumbnail_size' => 'thumbnail', 'show_post_views' => true, 'show_post_thumbnail' => false, 'show_post_excerpt' => false, 'no_posts_message' => __( 'No Posts', 'post-views-counter' ) );
Usage
pvc_most_viewed_posts( $args = array(), $display = true );
Parameters
- $args | array: Array of optional arguments.
- $display | bool: Return or echo the markup. Defaults to TRUE.
Return
The function returns an HTML markup that contains a list the five most viewed posts ordered by total views.
pvc_view_post()
Description
Allows the user to view a given post manually.
The function is located in the functions.php file of the plugin.
Usage
pvc_view_post( $post_id = 0 );
Parameters
- $post_id | int: Post ID
Return
The function returns a bool value. FALSE if the post doesn’t exist; TRUE if the post exists.
2 replies to "Developer’s API"
Hello, first of all thank you for such an incredible job. How would it be to bring the most viewed in a span of time? that is, I want to have the most viewed of the last 10 days. How would it be?
Hello,
I had problems using pvc_post_views()
var_dump(pvc_post_views($id,false)) is still a black box to me.
echoing worked out fine but using the return value for coding was a mission impossible.
pvc_get_post_views() much easier!!!
Nevertheless an awesome and very useful plugin. Thanks for sharing this great work.