Okay
  Public Ticket #3317720
Show author's posts
Closed

Comments

  • Artem started the conversation

    I would like to know if there is a way to show posts created by CURRENT user ? I would like to create a personal area for each user and there should be showing table with ONLY their posts.
    Im using Serialized PHP array source type and I wrote a WP Query for it screenshot
    Is this can be achieved with free version or some other addons required? Or its not possible at all?

  • Artem replied

    Well its really funny that developers didn't posted "wpdatatables_filter_php_array" filter in documentation list. 

    I solved my problem by investigating code which costed me a couple of hours of debugging. So to finish this task I added author id as a separate column inside WP Query

    $query_args = array(
        'post_type' => 'agreements',
        'posts_per_page' => '-1',
        'post_status' => 'publish',
    );

    $return_array = array();
    // The Query

    $the_query = new WP_Query( $query_args );

    // The Loop
    if ( $the_query->have_posts() ) {
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
            $author_id = get_post_field ('post_author', get_the_id());
            $return_array[] = array(
                'Agreement Execution #' => get_the_id(),
                'Concierge ID' => $author_id,
            );
        }
        /* Restore original Post Data */
        wp_reset_postdata();
    } else {
        // no posts found
    }
    echo serialize ($return_array);


    Solution:

    add_filter('wpdatatables_filter_php_array', 'show_rows_with_specific_id');
    function show_rows_with_specific_id( $PHPArray ) {
        foreach($PHPArray as $key => $value){
            if($value['Concierge ID'] != get_current_user_id()){
                unset($PHPArray[$key]);
            }
        }
        return $PHPArray;
    }


    For those who's looking for backend filtering I think that's the great option if you don't need to buy premium.

  •  1,819
    Miloš replied

    Hi, Artem.

    Firstly, I would like to sincerely apologize for the delayed response as we have been experiencing an unusually high number of tickets. I am sorry that it has taken longer than usual to respond to your concern and your patience is highly appreciated.

    -

    Yes, there are still some hooks that are not yet added to the Documentation.

    I will pass this to our developers,  we will do our best to add this filter to the available hooks in our Documentation section for Developers.


    Thank you very much for sharing this workaround solution with your code, 

    i am sure it will be useful for other users who might have the same use-case with the Lite version.

    You are correct,  for example advanced column filters that allow predefining filters for "user ID",

    or with dynamic placeholders such as VAR, %CURRENT_USER_ID% and others,  

    as well as our built-in "users see and edit only their rows" in editable tables is only available with Premium plugin version as more user-friendly options,

    but this workaround is useful for Lite version users that have coding skills.

    Thank you again for sharing this with us and other users.

    Of course, please don't hesitate to reach out to us with new tickets if anything else comes up.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •   Miloš replied privately