Get parameter from url and pass it in add_filter not returning dynamic value wordpress

451 Views Asked by At

I am facing a weird problem. I am trying to override value in a function using apply_filter.

Here is the code which I am using in the theme's functions.php file:

function customized_params_6e9668( $attrs ) {
    $subfolder = isset($_GET["sub"]) ? '/'.$_GET["sub"] : '';
    $attrs["folder"] = $attrs["folder"].$subfolder; // if getting the value from the url then not working in this case
    //$attrs["folder"] = $attrs["folder"]."/testing"; // if I use static name then working in this case
    echo $attrs["folder"];
    return $attrs;
}
add_filter( "customized_params_6e9668", "customized_params_6e9668");

Here is the function where I am using apply_filter to override the values in the plugin's file.

function getFolderData(){
    global $wpdb;
    $folder_data = $wpdb->get_row(
        $wpdb->prepare(
            'SELECT * FROM ' . $wpdb->prefix . 'folders WHERE key=%s',
            trim(sanitize_text_field($_REQUEST["data_key"]))
        )
    );
    if(!empty($folder_data)){
        $folder_data = apply_filters( 'customized_params_'.$folder_data->key, $folder_data );
        print_r($folder_data);
    }
}

This function is getting the list of data from the database. overriding the value of the folder using add_filter.

Please correct me where I am doing wrong.

Thanks in advance.

0

There are 0 best solutions below