WordPress.org

Support

Support » Themes and Templates » [Resolved] [Need Help] is_page array only work on first array item

[Resolved] [Need Help] is_page array only work on first array item

  • yotsugi

    @yotsugi

    Hi, I need help,,,

    I have conditional tag like this on my template:

    if ( is_page(array(493,491,14)) ) {
      //some code here
    }

    That’s work

    Then, I created theme options for page array so the code like this:

    if ( is_page(array($page_array)) ) {
      //some code here
    }

    where, $page_array = trim($options[‘different_page_style’]);
    But, it only works on page ID on first array item (493)

    I checked database for ‘different_page_style’ options and try to echoing, it has all three ID page.

    What’s wrong with my code?

    Thank’s before

    PS: Sorry for my bad English

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

    @alchymyth

    Forum Moderator

    if $page_array is already an array, you cant’t use array in here:

    if ( is_page(array($page_array)) ) {
      //some code here
    }

    try:

    if ( is_page($page_array) ) {
      //some code here
    }
    yotsugi

    @yotsugi

    Still not work 🙁

    Honestly, $page_array is not an array.
    $page_array is string input that has value ‘493,491,14’
    I don’t created $page_array as array.

    Found related thread here, but I still not understand.

    Michael

    @alchymyth

    Forum Moderator

    to turn $page_array from the string into an array, you need to ‘explode’ it:
    http://php.net/manual/en/function.explode.php

    $page_array = explode(',', $page_array);
    if ( is_page($page_array) ) {
      //some code here
    }
    yotsugi

    @yotsugi

    Thank’s

    It works!

    😀

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] [Need Help] is_page array only work on first array item’ is closed to new replies.
Skip to toolbar