Forums

[resolved] Using is_page with array (4 posts)

  1. vagamente
    Member
    Posted 1 year ago #

    Hi all.

    I'm trying to use the is_page conditional tag with array inside.

    I know that I can declare array inside is_tag, but can I use array of array?

    I mean something like this:

    $paginediservizio=array('355','992','988','990','592','882','528');
    $paginelinguabase=array('1167','1168','1169','1171');
    if (is_page(array($paginediservizio,$paginelinguabase) {
        [...]
    }

    It doesn't work. No errors, just doesn't output "true" in the right pages.

    Any suggestion why?

    Thanks

  2. Mark / t31os
    Moderator
    Posted 1 year ago #

    That's because you're passing in a multidimensional array, which won't work.. and additionally you're missing two right brackets on the is_page condition (might not exist in your actual code though).

    Merge the two arrays..

    $paginediservizio=array('355','992','988','990','592','882','528');
    $paginelinguabase=array('1167','1168','1169','1171');
    
    $merged_page_ids = array_merge( $paginediservizio, $paginelinguabase );
    
    if( is_page( $merged_page_ids ) ) {
    // Etc...

    Hope that helps..

  3. vagamente
    Member
    Posted 1 year ago #

    Yep... that solved it...

    Thanks

  4. Mark / t31os
    Moderator
    Posted 1 year ago #

    Happy to help.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags