Get Most Shared Posts Object

One of the most powerful feature of MashShare for a developer is the capability to get the shares of every single post for further development purposes like a Most Shared Posts widget. You can query the share values with the code below:
/**
 * Get Most Shared Posts Collection
 *
 * @param array $query_args Query arguments.
 *
 * @return array
 */
function prefix_mashshare_get_most_shared_query_args( $query_args ) {
	$defaults = array(
		'posts_per_page'      => 10,
		'ignore_sticky_posts' => true,
		'meta_key'            => 'mashsb_shares',
		'orderby'             => 'meta_value_num',
		'order'               => 'DESC',
		// This way we can be sure that only "shared" posts will be used.
		'meta_query'          => array(
			array(
				'key'     => 'mashsb_shares',
				'compare' => '>',
				'value'   => 0,
			),
		),
	);
	$query_args = wp_parse_args( $query_args, $defaults );
	return $query_args;
}

Still need help? Contact Us Contact Us