order by current user id in wordpress


To order queries by the current user ID in WordPress, you can use the get_current_user_id() function to retrieve the current user’s ID and then include it in your custom query. Here’s an example using the WP_Query class to retrieve posts ordered by the current user ID:

The issue with this snippet is it only gives the post of the current user ID and not posts by other users.

the following snippet lists down posts and order by the current user so that the current user post appears first and then the other post, you can use the same for other posts’ post_type as well.

This example assumes that you want to retrieve posts (you can change ‘post_type’,post_status to your custom post type and status if needed) authored by the current user and order them by user ID in ascending order.

,