Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author ka2

    (@ka2)

    Thank you for your inquiry.

    Yes, we are able to display data of the logged-in user only. There are several ways, I have example of when to add filter below.

    <?php
    function custom_select_query( $sql, $table_name, $sql_clauses ){
      if ( ! is_admin() && is_user_logged_in() && $table_name === 'sample' ) {
        global $cdbt;
        $current_user = wp_get_current_user();
        $where_clause = "user_id = '". (string) $current_user->ID ."'";
        $sql = sprintf( 'SELECT %s FROM %s WHERE %s %s', $sql_clauses[0], $table_name, $where_clause, $sql_clauses[2] );
      }
    
      return $sql;
    }
    add_filter( 'cdbt_crud_get_data_sql', 'custom_select_query', 10, 3 );

    Please include the above code in the “functions.php” etc. on the theme. However, it must be stored user ID in the data of the displaying table.

    Example of inserting the ID of the user who is logged in at the time of data registration, please try to see below (sorry in Japanese page).

    https://ka2.org/cdbt/v2/filter-reference/cdbt_before_insert_data/

    Thank you,

    Thread Starter hannatq

    (@hannatq)

    thank you Ka2 i will try this codes 🙂

    Thread Starter hannatq

    (@hannatq)

    hi ka2. mmay i know what is $sql_clauses for? sorry im still newby here. thanksss

    Plugin Author ka2

    (@ka2)

    Hi there,

    The third argument “$sql_clauses” on this filter is an array of the elements for generating the first argument “$sql”. Certinly so that does not need to use in the above example of the code.

    For example, if you want to use of complex query conditions when filtering the SQL, you can be used this argument for refer.

    Thank you,

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘show data of the logged user’ is closed to new replies.