Support

Account

Home Forums General Issues Using Page Link field with is_page()

Helping

Using Page Link field with is_page()

  • I’m trying to let users select the page(s) on which a custom post type will appear by using a Page Link custom field that allows for multiple selections.

    I’m getting post IDs like this:

    $alert_pages = get_field('alert_pages', false, false);

    Then imploding the array:

    $alert_page_array = "'".implode("','",$alert_pages)."'";

    Echoing $alert_page_array returns ’34’,’63’,’91’

    Using the following works:

    if( is_page( array ( '34','63','91' ) ) ) {

    But using the variable in there instead does not work:

    if( is_page( array( $alert_page_array ) ) ) {

    Can anyone see where I’m going wrong or if there’s a better way to use ACF for this purpose?

    Thanks.

  • You don’t need to us array in this statement

    
    if( is_page( array( $alert_page_array ) ) ) {
    

    that actually creates this

    
    if( is_page( array(array( '34','63','91' ) ) ) ) {
    

    just do

    
    if( is_page( $alert_page_array ) ) {
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Using Page Link field with is_page()’ is closed to new replies.