• Resolved sia77

    (@sia77)


    Hi there,

    I’m trying to exclude a post by id, so I have added the following code spinet to page_posts.php

    if ( isset( $atts['no_ids'] ) ) {
    	$post_no_ids = explode( ',', $atts['no_ids'] );
    	$this->args['post__not_in'] = $post_no_ids;
    	$this->args['posts_per_page'] = count( $post_no_ids );
    }

    And I commented out the following, because it seem it was interfering with get the excluded id assign to no__in_post

    if ( ! isset( $this->args['ignore_sticky_posts'] ) ) {
    	$this->args['post__not_in'] = get_option( 'sticky_posts' );
    }
    
    if ( ! isset( $this->args['ignore_sticky_posts'] ) ) {
    	$this->args['post__not_in'] = get_option( 'sticky_posts' );
    }

    Seems to be working partially, because my shortcode is actually is this:
    [ic_add_posts post_type='preamble,service' template='event_service1.php' no_ids='637']

    Now, there are two posts of type preamble, and several of type service, but what I see is a post of type preamble (the on that is not excluded), and post of type service are not listed.

    I ran the following:
    echo "<p>REQUEST:$wp_query->request</p>";
    but I get this:
    REQUEST:SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (wp_posts.ID = ‘629’) AND wp_posts.post_type = ‘page’ ORDER BY wp_posts.post_date DESC

    But when I run this:
    print_r($this->args);

    I get the following:
    Array ( [post_type] => Array ( [0] => preamble [1] => service ) [post_status] => publish [orderby] => date [order] => DESC [paginate] => [template] => event_service1.php [posts_per_page] => 1 [no_ids] => 637 [post__not_in] => Array ( [0] => 637 ) )

    Any ideas?
    Thanks,

    https://www.ads-software.com/plugins/posts-in-page/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter sia77

    (@sia77)

    I figured what my problem was. It’s working now.

    Thread Starter sia77

    (@sia77)

    So basically, add the first code snippet, and set ignore_sticky_posts to true in the shortcode, so you don’t have to comment out the second code snippet.
    In my case, I had to use two short code to get what I wanted….

    Plugin Author Eric Amundson

    (@sewmyheadon)

    Thanks sia77!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Excluding a post by ID’ is closed to new replies.