• Resolved ldeschenes

    (@ldeschenes)


    I have a query coded like this:
    query="select A, B, C, D, E, F where A='USER_APPARTEMENT' "

    and a Filter Funtion coded like this:

    function filter_gdoc_query ($query, $atts)
    {
    if ('https://docs.google.com/spreadsheets/--myfile1--/edit?usp=sharing' !== $atts['key']) { return $query; }
    $user_id = get_current_user_id();
    $key = 'appartement';
    $single = true;
    $appartement = get_user_meta( $user_id, $key, $single ); 
    return str_replace('USER_APPARTEMENT', $appartement, $query);
    }
    add_filter('gdoc_query', 'filter_gdoc_query', 10, 2);

    That is working fine for –myfile1–.

    Now I want to to the same for –myfile2-.
    Questions:
    1. Should I code a new Filter Function ?
    2. Should I modify the above Filter Function ?
    3. In both cases what would be the proper code ?

    Thanks in advance.

    • This topic was modified 9 years, 5 months ago by ldeschenes.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Meitar

    (@meitar)

    No one’s gonna write code foe you, but you’ve already got the right idea. You can do this either way, which way you choose is up to you.

    Thread Starter ldeschenes

    (@ldeschenes)

    I had the time to do some testing and I finally one function did the job.
    THe final code is :

    function filter_gdoc_query ($query, $atts)
    {
    $user_id = get_current_user_id();
    $key = 'appartement';
    $single = true;
    $appartement = get_user_meta( $user_id, $key, $single ); 
    return str_replace('USER_APPARTEMENT', $appartement, $query);
    }
    add_filter('gdoc_query', 'filter_gdoc_query', 10, 2);

    In fact, as it does not harm anything to parse every query, I just remove the part testing for the specific query :
    if ('https://docs.google.com/spreadsheets/--myfile1--/edit?usp=sharing' !== $atts['key']) { return $query; }

    Thanks again for the great plugin!
    .

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Multiple Filter Function’ is closed to new replies.