0

I have WordPress posts in combination with Advanced Custom Fields and FacetWP for filtering.

WordPress has an option to make a post sticky, I did this and nothing happenend so I tried to change my array in to this:

return array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 10,
    'cat' => '1,11',
    'post__in'  => get_option( 'sticky_posts' )
);

But this wil only return the sticky post and no other posts.

I want to make only one sticky at the top of all the results, anybody has an idea how I can manage to get it to work?

EDIT

Sorry if I was a bit unclear. I'm making a vacancies page with filters with FacetWP but I want an option to make one or more vacancies featured or sponsored. You got the standard sticky functionality of WordPress and that I tried but this is not going to work.

Is it possible to create an Advanced Custom Field checkbox where you can check or uncheck the "Featured" field and add this inside my loop and make the featured post always on top?

This is the loop in FacetWP I have so far:

<?php while ( have_posts()): the_post();?>
<div class="vacature-block">
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
        <div class="vacature-data">
            <div id="vacaturedatum"><?php echo get_the_date();?>
            </div>
            <div id="vacature" style="border: 1px #ededed solid;padding: 20px 10px 10px 10px;margin-bottom: 30px; border-radius: 5px;">
                <div id="vacaturetitel"><h2><?php the_title();?></h2></div> 
                <?php if ( in_category( 'vacatures')) {
                    $werkregio=get_field( "werkregio");
                    $aantal_uur=get_field( "aantal_uur");
                    if( $werkregio) {
                        echo '<div id="vacaturemeta"><i class="fa fa-map-marker-alt" aria-hidden="true" style="margin-right:5px"></i>' . $werkregio . '</div>';
                    }
                    else {}
                    if( $aantal_uur) {
                        echo '<div id="vacaturemeta"><i class="fa fa-clock-o" aria-hidden="true" style="margin-right:5px"></i>' . $aantal_uur . ' lesuren</div>';
                    }
                    else {}
                }

                if ( in_category( 'vervuld')) {
                    echo '<div id="vacaturevervuld">Vervuld</div>';
                }
?> 
                <div id="vacaturetekst"><?php the_excerpt();?></div>
            </div>
        </div>
    </a>
</div> <?php endwhile;?>

I already searched on Google and support of FacetWP but cant find something to start with.

  • OK, what exactly are you trying to achieve? It's a little bit confusing. Especially the part where you paste your code which is just a little fragment of it and it's pretty hard to guess the context... – Krzysiek Dróżdż May 31 '18 at 10:24
  • Sorry that it was a bit unclear, I edited my answer... Hope this makes more sense – user2812779 May 31 '18 at 10:36
0

Ok, I figured it out myself. So maybe I can help someone out with the same question.

I made a custom field TRUE / FALSE called "featured".

In facet WP I created this query:

<?php
return array(
    'post_type' => 'custom_post_type',
    'post_status' => 'publish',
    'meta_query' => array(
        'is_featured' => array(
            'key' => 'featured',
            'compare' => 'EXISTS'
        )
    ),
    'orderby' => array(
        'is_featured' => 'DESC'
    )
);

In FacetWP I used a simple if statement for the featured div:

<?php if ( get_field( 'featured' ) ): ?>
<div class="default-class featured">
<?php else: ?>
<div class="default-class">
<?php endif; ?>

Maybe not the best way to do it but it worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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