WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] !is_single(array()) Not Working (5 posts)

  1. Brandon_Orndorff
    Member
    Posted 1 year ago #

    I am trying to exclude certain posts by ID from showing a plugin and in the conditional statement I have the following:

    !is_single( array(get_option('ignore_posts')) )

    with ignore_posts holding the array of numbers stored as 150,160,174,177

    The issue is that it works to exclude post with ID 150 but none after that. Also if I change the order to make post ID 160 first then 160 is the only one to function as expected.

    Thank you in advance for any insight you have.

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    are you entering the array manually, or do the numbers come from some options or custom fields?

    i.e. are you absolutely sure you are using an array, or could it be a string with comma-separated numbers?

  3. Brandon_Orndorff
    Member
    Posted 1 year ago #

    I am saving the numbers from a custom field in the admin area and calling them in with get_option('ignore_posts')

    What is saved to the database is 150,160,174,177 //while testing

    So I guess is is a string with comma separated values

  4. You might need to explode the string into an array.

    $ignore = get_option( 'ignore_posts' );
    
    if ( ! is_array( $ignore ) )
        $ignore = explode( ',', $ignore );
    
     if ( ! is_single( $ignore ) ) {
         //.....
  5. Brandon_Orndorff
    Member
    Posted 1 year ago #

    Perfect!

    Thank you both for your help, works great.

Topic Closed

This topic has been closed to new replies.

About this Topic