- This topic has 23 replies, 8 voices, and was last updated 5 months, 1 week ago by
Fernando.
-
AuthorPosts
-
March 30, 2021 at 1:15 am #1714968
Evonne
Hello,
Theme template: Dispatch
I have been searching for 2 days to see if there was anything that can help me create a “Most Popular” posts of all time just below the Header element. I liked that the Header element already displays the latest posts. I am already using WP Show Posts but it doesn’t sort based on page views and I can’t figure out how Elements work…
I don’t really want to look for another plugin just for this.
March 30, 2021 at 4:34 am #1715110David
StaffCustomer SupportHi there,
you can simply add another WP Show Posts list to either the home page content.
In this topic here, Elvin provides the shortcode method ( and a filter ) for ordering the list based on
post_views_count
February 21, 2022 at 5:09 am #2127357Morgan
I got a syntax error, unexpected token “=>” on this row:
$args[‘meta_query’] => array(February 21, 2022 at 6:40 am #2127470David
StaffCustomer SupportHi There,
did you copy Elvins code exactly?
As that could be related to a syntax issue, such as curly quotes instead of'
straight quotes in the preceeding argumentFebruary 21, 2022 at 6:44 am #2127476Morgan
Yes i copied it. It looks like this:
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; } );
February 21, 2022 at 8:15 pm #2128390Elvin
StaffCustomer SupportHi Morgan,
Ah right there’s actually a syntax issue there as you’ve pointed. (I’ve corrected the one from WPSP now)
Let’s correct this one as well.
Try this:
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; } );
Reminder: You’ll also have to make this change in your wp-show-posts.php file: https://github.com/tomusborne/wp-show-posts/commit/286caf1164db8b6b6f38b85d3a011b519a27f4de – for the filter to work properly. (You can skip this if you’re using the beta version – https://wpshowposts.com/wp-show-posts-1-2-0/)
Also make sure to change
123
to the WPSP list ID you’re going to use this on. 🙂February 22, 2022 at 12:43 am #2128550Morgan
Hi Elvin,
No i get his:
Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in wp-includes/class-wp-hook.php on line 307 and exactly 2 expected in wp-content/themes/generatepress_child/functions.php:24 Stack trace: #0 wp-includes/class-wp-hook.php(307): {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
February 22, 2022 at 2:09 am #2128614Elvin
StaffCustomer SupportWere you able to do the required code edits on WPSP’s
wp-show-posts.php
file? it’s important to make this code snippet work. 😀February 22, 2022 at 2:28 am #2128641Morgan
I added this to wp-ashow-posts.php:
$query = new WP_Query( apply_filters( 'wp_show_posts_shortcode_args', $args ) ); $query = new WP_Query( apply_filters( 'wp_show_posts_shortcode_args', $args, $settings ) );<code></code>
And this to function file:
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; } );
Dont know what im doing wrong here but i still gets this:
Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in wp-includes/class-wp-hook.php on line 307 and exactly 2 expected in wp-content/themes/generatepress_child/functions.php:20
Stack trace:
#0 wp-includes/class-wp-hook.php(307): {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(570): 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 22, 2022 at 9:00 pm #2129957Elvin
StaffCustomer SupportAh that’s the issue.
This line:
$query = new WP_Query( apply_filters( 'wp_show_posts_shortcode_args', $args ) );
Has to be replaced with this line:
$query = new WP_Query( apply_filters( 'wp_show_posts_shortcode_args', $args, $settings ) );
We need the
$settings
passed to the filter so we can target a specific list. 🙂February 22, 2022 at 11:59 pm #2130043Morgan
Its not working for me. Now i get this:
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 12:19 am #2130059Elvin
StaffCustomer SupportThe error is still saying the change to the plugin’s code wasn’t applied (or applied properly). Perhaps I wasn’t clear. My apologies.
Any change you can copy the site to a staging site or let us have temporary backend access to the site you’re working on to check if it’s applied properly?
You can use the private information text field to provide the details –
https://docs.generatepress.com/article/using-the-premium-support-forum/#private-informationFebruary 23, 2022 at 12:26 am #2130065Morgan
Ok,
I’ll fix that. No problem it’s a staging site. I have sent you the credentials now.
February 23, 2022 at 12:35 am #2130075Elvin
StaffCustomer SupportI’ll fix that. No problem it’s a staging site. I have sent you the credentials now.
did you send it through our contact page? The system has yet to receive it.
I just realized you’re not the topic starter of this thread. lol.
Can you open a new one? So you can use the private information text field –
https://docs.generatepress.com/article/using-the-premium-support-forum/#private-informationFebruary 23, 2022 at 12:37 am #2130076Morgan
I opened a new support topic as i dont have the private field in this.
-
AuthorPosts
- You must be logged in to reply to this topic.