samedi 9 septembre 2017

Problems with functions.php

function getParentID() {
    $url = 'http://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ];
    $pageID = url_to_postid($url);
    $pageID = trim($pageID);
    return $pageID;
}

function OrderFieldsQuery($args) {

    //->> WORKS WITH HARD-CODED ID'S
    $args['post_parent'] = 52;

    $args['post_parent'] = getParentID();
    // Doesn't work in that way, even function returns same value;

    return $args;
}

add_filter('acf/fields/relationship/query', 'OrderFieldsQuery', 10, 1); // add key to filter

Then i use these arguments for filtering (search - box for ACF).

What could be the problem? Bug is really interesting, because it works when hard-coded, but doesn't using function value.

Tried converting $pageID from url to int, because it works with hardcoded number value. Didn't work either.

functions.php file.




Aucun commentaire:

Enregistrer un commentaire