0

I have a website in development and the customer wanted a news and F.A.Q page. Not a problem! He wanted to be able to add his own posts (to both news and F.A.Q.. Again, not a problem! The last thing he requested was that he was able to manage the amount of posts showing and what kind of posts that were shown. Now this is where i got confused. I've already build a system where the customer can select a category to show. (i'm using AwesomeBuilder for this). Now we have three different types of posts. Regular, Regular + Sticky, and Sticky. Should the client select the option to only show Regular posts i can turn the sticky posts off by using post__not_in. However if the client selects either Regular + Sticky or Sticky the amount function doesn't work anymore.

Lets say the client selects a maximum amount of 10 posts. At the regular category this gets maxed at 10 and that's it. At the sticky posts however this doesn't happen, it just shows all the sticky posts since stickies are told to always stay on top. Regular + Sticky would show all the sticky posts followed by 10 regular posts. I hope my situation and problem is clear.

Code below.

$sticky = get_option( 'sticky_posts' );
$number = $atts['number'];

if ($atts['sticky'] == 'nieuws') {
    $args = array('post__not_in'  => $sticky, 'posts_per_page' => $number );

} elseif ($atts['sticky'] == 'nieuws-sticky') {
    $sticky_count = count($sticky);
    if ($sticky_count <= $number){
        $number_sticky = $number - $sticky_count;
        $args = array('post_type' => post, 'posts_per_page' => $number_sticky);
    }
    else {
//      $sticky = array_slice($sticky,0, 1);
//      echo 'hello'. $sticky;
        $args = array('post__in'  => $sticky );
    }
} else {
//  $sticky = array_slice($sticky,1, 2);
    $args = array('post__in'  => $sticky, 'posts_per_page' => $number );
}

ps. I know THIS is the about the same question but it hasnt been answered yet.

2 Answers 2

0

Make sure that the $number variable is getting 10, and also make sure that you are using the $args in the query_posts functions, like query_posts($args);

3
  • The $number is being set by a user defined slider. It's getting the right variable this has been checked by the fact that the "regular" posts work fine. Sep 29, 2014 at 14:56
  • $args = array( 'showposts' => $number ); Sep 29, 2014 at 17:45
  • Thanks for your code Pedro, it doesnt overrule the sticky posts however they still all show on top of my page. Sep 30, 2014 at 7:19
0

https://codex.wordpress.org/Sticky_Posts

You can refer to this "Display just the first sticky post, if none return the last post published: " from the link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.