• Hi,

    Is there a function or filter that is returning the current id used by the shortcode?
    I am using the following code to display based on meta box. But I want to exclude only the current displayed posts from the wp loop. Once the post is not in the scope. It should be visible in the main wp query.
    echo do_shortcode('[display-posts post_type="post" category_id="' . $cat_id . '" meta_key="featured_box_check" meta_value="on" ignore_sticky_posts="true" image_size="slider-staged" posts_per_page="5" wrapper="ul" wrapper_class="category-slider" include_excerpt="false" include_date="true" date_format="d.m.Y" post_status="publish" no_posts_message="' . $no_featured_posts_message . '" orderby="date" order="DESC"]');

    I tried to use the below function, but it has one major issue, that we have to go manually and uncheck the boxes in order for the posts to be visible in the main loop.

    function exclude_featured_post( $query ) {
        if ( $query->is_archive() && $query->is_main_query() ) {
            $meta_query = $query->get('meta_query') ? $query->get('meta_query') : array();
            $meta_query[] = array(
                'key' => 'featured_box_check',
                'value' => '0',
                'compare' => 'NOT EXISTS'
            );
            $query->set('meta_query', $meta_query);
        }
    }
    add_action( 'pre_get_posts', 'exclude_featured_post' );

    Kind Regards,
    Dimitar

The topic ‘Get current post_ids used by the shortcode’ is closed to new replies.