WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Need Help] is_page array only work on first array item (5 posts)

  1. yotsugi
    Member
    Posted 3 years ago #

    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

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    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
    }
  3. yotsugi
    Member
    Posted 3 years ago #

    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.

  4. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    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
    }
  5. yotsugi
    Member
    Posted 3 years ago #

    Thank's

    It works!

    :D

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.