Okay
  Public Ticket #1344397
Filter on current user, Serialized PHP array
Closed

Comments

  •  2
    Privattina started the conversation

    Will I be able to filter posts on currently logged in user if I build my custom wp_query and call it as a "Serialized PHP array".

    I have been reading the forum and it looks get_current_user_id is not available when wpDataTables calls the file?

    I have this, will it work?:

    $return_array = array();
    $filtered_posts = get_view_query_results(18635);

    foreach ($filtered_posts as $filtered_post) {
        $post_author = get_post_field('post_author', $filtered_post->ID);
        if (get_current_user_id() == $post_author) {
            $return_array[] = array(
               //multiple 'label' => get_post_meta(),
            );
        }
    }
    echo serialize($return_array);

  • [deleted] replied

    Hi Privattina,
    Thank you for your inquire. 

    i really would like to help you but this is more of the question for creator of the function that you intent to use then for us. If you can write your code in a way that it will return desirable data in format that is described in our Documentation I am sure that it will work in our plugin. If it doesn't please feel free to open a ticket in corresponding section of this support and one of our agents will help you with the issue  

  •  2
    Privattina replied

    Maybe I wasn't clear in my question. I have no problem with creating the function. My question is if I will be able to filter on current user. I have read in the forum threads that indicate that "current user" is not available if you create a table from a wp_query. 

    I tried to post as a support ticket but I was not allowed.

    In my test current user returns 0

  • [deleted] replied

    Hi Privattina,

    If I understood you correctly you try to find a way to filter the table by user?

    If this is the case you have an option to prefilter the table by entering “Predefined values” and there you can use placeholder %CURRENT_USER_ID% to filter the table by user ID.