[Support request] “Most Popular” posts today

Home Forums Support [Support request] “Most Popular” posts today

Home Forums Support “Most Popular” posts today

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #2130115
    Morgan

    Im following this thread:
    https://generatepress.com/forums/topic/create-a-most-popular-or-most-viewed-posts-section-on-cover-page/

    Trying to set up a Most Popular Posts today, but it’s not working for me. Gets this error:

    Dina ändringar i PHP-kod har återställts till tidigare version på grund av ett fel på rad 24 i filen wp-content/themes/generatepress_child/functions.php. Korrigera och försök spara en gång till.

    Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in wp-includes/class-wp-hook.php on line 309 and exactly 2 expected in wp-content/themes/generatepress_child/functions.php:24
    Stack trace:
    #0 wp-includes/class-wp-hook.php(309): {closure}()
    #1 wp-includes/plugin.php(189): WP_Hook->apply_filters()
    #2 wp-content/plugins/wp-show-posts/wp-show-posts.php(383): apply_filters()
    #3 wp-content/plugins/wp-show-posts/wp-show-posts.php(569): wpsp_display()
    #4 wp-includes/shortcodes.php(356): wpsp_shortcode_function()
    #5 [internal function]: do_shortcode_tag()
    #6 wp-includes/shortcodes.php(228): preg_replace_callback()
    #7 wp-includes/class-wp-hook.php(307): do_shortcode()
    #8 wp-includes/plugin.php(189): WP_Hook->apply_filters()
    #9 wp-includes/post-template.php(253): apply_filters()
    #10 wp-content/themes/generatepress/content-page.php(73): the_content()
    #11 wp-includes/template.php(772): require(‘/home/718213.cl…’)
    #12 wp-includes/template.php(716): load_template()
    #13 wp-includes/general-template.php(204): locate_template()
    #14 wp-content/themes/generatepress/inc/theme-functions.php(568): get_template_part()
    #15 wp-content/themes/generatepress/page.php(34): generate_do_template_part()
    #16 wp-includes/template-loader.php(106): include(‘/home/718213.cl…’)
    #17 wp-blog-header.php(19): require_once(‘/home/718213.cl…’)
    #18 index.php(17): require(‘/home/718213.cl…’)
    #19 {main}
    thrown

    #2130120
    Elvin
    Staff
    Customer Support

    The edit on the plugin seems fine.

    What happens if you try this variation of the filter?

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 123 === $settings['list_id'] ) {
            $args['meta_query'] = array(
                array(
                    'key' => 'post_views_count',
                    'orderby' => 'meta_value_num',
                    'order' => 'DESC',
                )
            );
        }
        return $args;
    },20 ,2 );

    Reminder: on the line 123 === $settings['list_id'] change 123 to the WPSP list id you wish to apply this change on.

    #2130125
    Morgan

    Then i get this:

    Dina ändringar i PHP-kod har återställts till tidigare version på grund av ett fel på rad 26 i filen wp-content/themes/generatepress_child/functions.php. Korrigera och försök spara en gång till.

    syntax error, unexpected token “=>”

    #2130142
    Elvin
    Staff
    Customer Support

    I’ve edited the code.

    Can you try it again? I’ve removed the cause of that issue. it was an extra > that should’ve been just =.

    #2130197
    Morgan

    Thanks, code seems fine now, but it says “No posts found” in the widget view?

    #2130210
    Elvin
    Staff
    Customer Support

    If it didn’t find any posts, that means the params we’ve used didn’t match of the posts on your site.

    You’ll have to modify it to your preference.

    Now comes the tricky part. How do you determine “Popular” posts on your site?

    The code I’ve provided assumes you have some sort of function that counts the number of views of a post.

    This one doesn’t come with WPSP by default, you’ll have to make this or get it from a plugin.

    If you determine what’s “Popular” in a different manner, you’ll have to change the array params within the $args['meta_query'] to match that.

    #2130215
    Morgan

    Okay,

    I did set up a WP Show Post-list and i thought that would work with the code.

    Maybe i’m better of looking for a plugin. I do not like to have to many plugins and was hoping this could be be done with GP + WP Show Post + this code in the function file.

    #2131399
    Elvin
    Staff
    Customer Support

    Maybe i’m better of looking for a plugin. I do not like to have to many plugins and was hoping this could be be done with GP + WP Show Post + this code in the function file.

    That may actually be more efficient if there’s actually one existing. 🙂

    #2131491
    Morgan

    Okay, yes i found a couple. Trying them out now. Thanks. 🙂

    #2131495
    Elvin
    Staff
    Customer Support

    Hopefully, you get one that works specifically to your preference.

    While these plugins are outside of our scope of support, they should work w/ GP if they work on a default WordPress theme. 😀

    #2133313
    Morgan

    Yes, found one that seems to work as expected. Thanks for your support.

    #2135942
    Elvin
    Staff
    Customer Support

    No problem. 😀

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.