• Resolved wavematt

    (@wavematt)


    I have been following the documentation and examples closely and I was happy to use the wpp_custom_html filter to build the output myself and avoid using it as a widget. However, for me the $popular_posts param in the filter’s callback is an html string and not an array of posts, as documented. Is there something that I can do to fix this? Here are the steps I have completed so far to get to this point:

    * Install and activate plugin in WP admin
    * Use wpp_get_mostpopular() on template page
    * Create wpp_custom_html filter to customize HTML output
    * BLOCKED – Can’t loop because $popular_posts param is a string, not an array

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hey Matt,

    From the profile picture you must be the same guy from Github, right? ??

    Anyways, without seeing some actual code I can’t help you out.

    Also:

    • PHP version?
    • Plugin version?
    Thread Starter wavematt

    (@wavematt)

    Hey Hector,

    Yep that’s me haha.

    PHP version is 7.0.31
    Plugin version is 4.1.1
    Sage Theme version is 9.0.0

    Below is a summary of the code I have implemented so far with popular posts.

    Thank you for your help btw ??

    Blade Template which calls wpp_get_mostpopular():

    
    $category = get_the_category()[0]->cat_ID;
    
    {{ wpp_get_mostpopular([
      'range'    => 'all',
      'order_by' => 'views',
      'cat'      => $category->parent,
      'limit'    => 5
    ]) }}
    

    WPP Filter to create custom output:

    
    // My filter just passes $popular_posts to my blade template
    // The issue in this filter is $popular_posts is a string, not an array
    add_filter('wpp_custom_html', function ($popular_posts, $instance) {
        $data = [
            'popular_posts' => $popular_posts
        ];
    
        return sage('blade')->render('partials.popular-posts', $data);
    }, 10, 2);
    

    Blade Template to render the custom html:

    
    @foreach ($popular_posts as $popular_post)
      // render each post
    @endforeach
    

    Even without the blade usage, I could still build this HTML string by looping through the posts, but again – that’s where I’m stuck because its a string and not an array.

    • This reply was modified 6 years, 6 months ago by wavematt.
    • This reply was modified 6 years, 6 months ago by wavematt.
    Thread Starter wavematt

    (@wavematt)

    Okay I resolved my own issue. Sorry, this theme I’m working on had a custom plugin that was conflicting with the Popular Posts plugin. Once I deactivated the conflicting plugin, my code started working. Thanks for your help Hector! Sorry for the confusion!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Popular posts param from wpp_custom_html is a string, not an array’ is closed to new replies.