WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] sticky post_type? (3 posts)

  1. Anointed
    Member
    Posted 4 years ago #

    I created new post_type and it works. But why do I not have the option to make my custom single post 'sticky'?

    Do I need to add the ability when creating the post_type?

  2. MichaelH
    Member
    Posted 4 years ago #

    Sticky posts are a special animal but they are posts, not a different post type. You'll have to use a special loop to display that particular post type. Here's an example where a custom field key of sticky and a value of yes qualify this post type of book to be displayed:

    <?php
    $args=array(
      'meta_key'=>'sticky',
      'meta_value'=> 'yes',
      'post_type' => 'book',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Books with sticky = yes custom field';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        the_content();
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. Anointed
    Member
    Posted 4 years ago #

    Thank you Michael

    I completely misunderstood the functionality behind sticky posts. I was under the wrong impression that when I created a new post_type, that the ability to make a custom post_type 'sticky' via the same drop down would be there.

    Saved me tons of head banging

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags