Adding query string to multiple page urls in a Wordpress function

by andreasherne   Last Updated May 15, 2019 19:08 PM

I have a wordpress function that adds a query string 'nocfcache=1' to a single page url.

function nocfcache_query_string( $url, $id ) {
    if( 42 == $id ) {
        $url = add_query_arg( 'nocfcache', 1, $url );
    }
    return $url;
}

add_filter( 'page_link', 'nocfcache_query_string', 10, 2 );

Issue: How to use multiple page ids in the function so as to make sure they will all have the query string appended to the url.

What I have tried so far:

function nocfcache_query_string( $url, $id ) {
    $id = array (399, 523, 400, 634, 636, 638);
    if(in_array($post->ID, $id)) {
        $url = add_query_arg( 'nocfcache', true, get_permalink( $post->ID ));
        return $url;
        exit;
    }
}

add_filter( 'page_link', 'nocfcache_query_string', 10, 2 );


Related Questions


Updated December 07, 2016 08:03 AM

Updated June 12, 2015 02:03 AM

Updated July 14, 2015 15:03 PM

Updated May 23, 2016 09:03 AM

Updated January 29, 2019 11:08 AM