0
votes

My version of wordpress is 5.2.3

I have a custom post type and I want to add it a sticky post. I tried many plugins and hack to figured out how to solved this problem (sticky custom post type isn't a native feature of wordpress) but I still don't know how to solved it.

Does anyone have a solution for me ?

-----EDIT------

I try this plugin https://wordpress.org/plugins/custom-post-type-sticky/. He put the same feature than the classic post of wordpress (a checkbox for put a sticky post) he works perfectly in back but nothing appear in front. (event with an additional code found here https://www.sktthemes.org/wordpress/add-sticky-posts-wordpress/) My code is a basic loop like :

<?php
  $args_ressource = array(
    'post_type'           => 'ressource',
    'order'               => 'DESC',
    'posts_per_page'      => 4,
  );

  $ressource = new WP_Query( $args_ressource );

  if ( $ressource->have_posts() ) { ?>
    <ul>
      <?php 
        while ( $ressource->have_posts() ) {
        $ressource->the_post(); 
        $imageArticle = get_field('hero_image');
      ?>

        <li>
          <a href="<?php the_permalink(''); ?>">
           <?php the_title(); ?>
          </a>
        </li>

      <?php } ?>
    </ul>
  <?php } 
  wp_reset_postdata();
?>

To be precise I need to show my sticky custom post type on the left of my page, and on the right the rest of the custom post but without this sticky post.

With the basic article a simple loop works because this is a basic feature of wordpress, but not with custom post type

Many thanks

1
What plugins have you tried? What code have you tried?disinfor
You must code this feature. WP doesn't know about your CPT. You can do something like add a custom checkbox to your custom posts that if checked make a post sticky, then in your templates that output the posts write a little code that checks for the sticky checkbox and outputs accordingly. Custom is custom...BugsArePeopleToo
Hello thanks for replying. I edit my post with more explanation and code.Freya
Hello @BugsArePeopleToo, yesI have already thought about this solution but i dont know how to exclude this post to my second list. I dont want my sticky post repeat two times on the same page.Freya
@Freya This is very broad, several topics at play here and so many ways to achieve it. Research how to parse an array and separate items into 2 new arrays, that may help you conceptualize how you want to handle the data in your templates.BugsArePeopleToo

1 Answers

0
votes

admin: Create meta_value mimicking sticky function on/off

logic: query "posts" filtering only checked posts create second query where you exclude above "post" ids

template: run a loop for sticky run the common loop