- This topic has 11 replies, 2 voices, and was last updated 2 years, 1 month ago by Elvin.
-
AuthorPosts
-
February 23, 2022 at 1:29 am #2130115Morgan
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}
thrownFebruary 23, 2022 at 1:37 am #2130120ElvinStaffCustomer SupportThe 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.February 23, 2022 at 1:39 am #2130125MorganThen 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 “=>”
February 23, 2022 at 2:05 am #2130142ElvinStaffCustomer SupportI’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=
.February 23, 2022 at 2:55 am #2130197MorganThanks, code seems fine now, but it says “No posts found” in the widget view?
February 23, 2022 at 3:04 am #2130210ElvinStaffCustomer SupportIf 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.February 23, 2022 at 3:08 am #2130215MorganOkay,
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.
February 23, 2022 at 9:42 pm #2131399ElvinStaffCustomer SupportMaybe 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. 🙂
February 24, 2022 at 12:25 am #2131491MorganOkay, yes i found a couple. Trying them out now. Thanks. 🙂
February 24, 2022 at 12:32 am #2131495ElvinStaffCustomer SupportHopefully, 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. 😀
February 25, 2022 at 6:44 am #2133313MorganYes, found one that seems to work as expected. Thanks for your support.
February 27, 2022 at 5:34 pm #2135942ElvinStaffCustomer SupportNo problem. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.