Tips & Tutorial

How to Display WordPress Post Only from Current User

Oleh takien

Do you want to display your users’ posts only for posts they own when they logged in? By using the following code, you can do that.

Here is the code, place it on your funtions.php file on your current theme.

function display_post_only_current_user( $query ) {
    if ( is_admin() ) {
        $query->set( 'author', get_current_user_id() );
    }
}
add_action( 'pre_get_posts', 'display_post_only_current_user' );

Tulisan ini sudah berumur: 11 tahun 8 bulan 2 hari. Informasi di dalamnya mungkin sudah tidak relevan, tapi nilai historisnya sangat berharga, terutama bagi saya sebagai penulisnya.