G
G
Galyanoff2018-05-26 15:10:45
WordPress
Galyanoff, 2018-05-26 15:10:45

How to exclude received posts from the main cycle for registered users?

Greetings!
How can I exclude posts from the main loop (index.php) that I get from the Favorite Post plugin?
I get bookmarked posts from the plugin like this:

$favorites = WeDevs_Favorite_Posts::init()->get_favorites();

I put them on a separate page. But from the main they should be removed for registered users.
The cycle on the main one from which I want to remove:
<?php
    if ( have_posts() ) :

      /* Start the Loop */
      while ( have_posts() ) :
        the_post();

        get_template_part( 'template-parts/content', get_post_type() );

      endwhile;

      the_posts_navigation();

    else :

      get_template_part( 'template-parts/content', 'none' );

    endif;
    ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Galyanoff, 2018-05-27
@Galyanoff

He asked, answered himself)
did this:
$favorites = WeDevs_Favorite_Posts::init()->get_favorites(); // Get posts
$post_ids = wp_list_pluck( $favorites, 'post_id' ); // Collect into an array with ID
query_posts(array( 'post__not_in' => $post_ids )); // Exclude from the loop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question