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

    (@hcabrera)

    Hi there!

    I know the feeling, been there too haha.

    The only way you could do this would be by hooking into WPP to build a custom HTML markup and then inject the sticky post at the top. Something like this:

    function my_custom_popular_posts_html_list( $popular_posts, $instance ){
    
      $output = '<ul class="wpp-list">';
    
      $sticky = get_option( 'sticky_posts' );
      $args = array(
        'posts_per_page' => 1,
        'post__in'  => $sticky,
        'ignore_sticky_posts' => 1
      );
      $query = new WP_Query( $args );
    
      if ( isset($sticky[0]) ) {
    
        // Inject here your stick post(s).
        if ( $query->have_posts() ) {
    
          // This is your old, trusty WordPress loop!
          while ( $query->have_posts() ) {
    
            the_post();
    
            // Here goes the HTML output of your sticky post.
            // Make sure you use here the functions that return data instead of echoing them (eg. get_the_title() instead of the_title()).
    
          }
    
          // Restore original post data.
          wp_reset_postdata();
    
        }
    
      }
    
      // Loop the list of popular posts.
      foreach( $popular_posts as $popular_post ) {
    
        // Here goes the HTML output of your popular post.
    
      }
    
      $output .= '</ul>';
    
      return $output;
    
    }
    add_filter( 'wpp_custom_html', 'my_custom_popular_posts_html_list', 10, 2 );

    You will want to check the sample code to learn how to use the different variables to build the HTML output.

    Let me know if you need help with this, alright?

    Thread Starter Chuck Reynolds

    (@ryno267)

    yup got it. that’s fairly simple – i was thinking more about weighting the metafield entry if a post was stickied but this is easier and I don’t need anything more advanced at the moment.

    also you forgot the $query-> before the_post(); but I know what you meant ??

    Thanks man.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘sticky post have priority at top?’ is closed to new replies.