WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] !is_single(array()) Not Working

[Resolved] !is_single(array()) Not Working

  • 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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael

    @alchymyth

    Forum Moderator

    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?

    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

    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 ) ) {
         //.....

    Perfect!

    Thank you both for your help, works great.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] !is_single(array()) Not Working’ is closed to new replies.
Skip to toolbar