• Resolved SUoC9000

    (@superuserofcourrse)


    Hello !

    Thank you for the fantastic plugin!
    I noticed a perfect fit solution at the bottom of the Other Notes tab mentioning using qdoc_query in the short code to visually return only data related to the user login in on wordpress by getting “outside content”. I don’t see a good example code of this though. Anything would be very appreciated for tie-ing those together. Thank you for any further information…

    https://www.ads-software.com/plugins/inline-google-spreadsheet-viewer/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Meitar

    (@meitar)

    I noticed a perfect fit solution at the bottom of the Other Notes tab mentioning using qdoc_query in the short code to visually return only data related to the user login in on wordpress by getting “outside content”. I don’t see a good example code of this though. Anything would be very appreciated for tie-ing those together. Thank you for any further information…

    Sure. It’s just a standard WordPress filter, which you can/should learn about in the Codex. If, for example, you wanted to do a GQL query on a Google Spreadsheet but select only rows that match the current user’s email address, you might write a gdoc shortcode like this:

    [gdoc key="ABCDEFG" query="select A, B, C where X = '__WORDPRESS_USER_EMAIL__'"]

    and then, in your plugin or theme or whatever, a WordPress filter function like this:

    function filter_gdoc_query ($query, $atts) {
        if ('ABCDEFG' !== $atts['key']) { return $query; }
        $cur_user = wp_get_current_user();
        return str_replace('__WORDPRESS_USER_EMAIL__', $cur_user->user_email, $query);
    }
    add_filter('gdoc_query', 'filter_gdoc_query', 10, 2);

    In this example, when a logged-in user whose email address is [email protected] loads the page on which a gdoc shortcode with the key of ABCDEFG is inserted, the resulting query to the Google Sheet will be:

    select A, B, C where X = '[email protected]'

    All other gdoc shortcodes will simply be passed on unchanged.

    Hope this helps.

    Plugin Author Meitar

    (@meitar)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘qdoc query under "Other Notes" bottom of screen example request’ is closed to new replies.