List all posts from specific category ordered by access count via shortcode
-
Hi Ajay,
first of all: Thanks a lot for this awesome plugin! Helped me a lot.
I’m trying to implement some custom post list on a page using get_tptn_pop_posts within a self-made shortcode.
I would really appreciate your advice on a problem I’m encountering …Objective:
– List posts links from a specific category on a page
– Category slug: ablagesystem
– category ID: 4
– Posts ordered by access count top-down
– Number of posts limit: none (display all posts)
– Relevant count time range: 30 days
– List style: unordered
– Implement via shortcode (no template coding wanted)
– Link: https://hochproduktiv.de/ablage-organisieren-dokumente-verwalten-buero-privat-zu-hause-dokumentenmanagement-ablagesystem/Code in functions.php:
function tptn_shortcode_ablagesystem( $atts, $content = null ) { if ( function_exists( 'get_tptn_pop_posts' ) ) { $list =''; $settings = array( 'daily' => TRUE, 'daily_range' => 30, 'strict_limit' => FALSE, ); $topposts = get_tptn_pop_posts( $settings ); // Array of posts $topposts = wp_list_pluck( $topposts, 'postnumber' ); $args = array( 'post__in' => $topposts, 'orderby' => 'post__in', 'post_type' => 'post', 'cat' => '4', ); $my_query = new WP_Query( $args ); if ( $my_query->have_posts() ) { $list = '<ul>'; while ( $my_query->have_posts() ) { $my_query->the_post(); $list = $list . '<li><a href="' . get_permalink( get_the_ID() ) . '">' . get_the_title() . '</a></li>'; wp_reset_postdata(); } $list = $list . '</ul>'; } else { } wp_reset_query(); return $list; } } add_shortcode( 'tptn_list_ablagesystem', 'tptn_shortcode_ablagesystem' );
Problem:
– Seven posts in respective category online
– Only five displayed (should be seven), seems to restrict to five regardless of arguments
– Not sure, if $settings are considered
– Not sure, if post ranks / post order are stored in ‘postnumber’Do you have any idea as to where I went wrong?
Thanks for your help in advance!Robert
- The topic ‘List all posts from specific category ordered by access count via shortcode’ is closed to new replies.