You can try below code –
<?php
global $current_user;
if ((is_user_logged_in() && $current_user->ID == $post->post_author) || current_user_can( 'manage_options' )) {
echo 'my post';
}
?>
Check below link also-
https://codex.wordpress.org/Function_Reference/current_user_can
Related Posts:
- Hide posts from users with a specific role
- How to order posts by custom WP role?
- SQL User Query by Multiple Roles using PHP
- How to order posts in wp_query by the user role (2 roles in array)
- How to display user order by role
- How can I query users by custom role?
- Why does get_posts only show results for Admins or logged-out users?
- Show menus to one admin username
- Link Author URL’s based on a custom field
- Meta query orderby meta_value_num sorting by role first
- Set “editor” role to existing user
- Pre_get_posts only show posts by administrator roles
- WP_Query: Query posts only if their access is restricted to logged user’s role
- Displaying content to search engines but via navigation only for registered users.
- Get users query makes the site loading time too big?
- How to know which editor published a post programmatically?
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- Wp_redirect and sending variables
- Sanitation needed for WP_Query or get_posts calls?
- how does $wpdb differ to WP_Query?
- WP_Query – filter or directly?
- replace the WP_Query class in the main query
- How can I save an array from a random post sequence for later use?
- Does WordPress generate an automatic page for post formats?
- Why is WP-Query spelled like it is?
- Limit search results to exact match
- WP_Query hit max joins… How else can I build a search function that uses custom fields?
- Pagination not working Search posts
- Order terms inside a select dropdown
- WP_Query Filtred by author name ( Return null )
- How can i make WP_Query return post image and categories?
- How to add terms to my tax_query based off of the current post
- Get image of latest post from taxonomies/categories
- Using $paged redirects /page/2 to page 1
- Why wont this wp_query exclude certain pages?
- WP_Query attachments by multiple IDs
- WP_Query returning no results
- wp_query not searching with apostrophe
- pre_get_posts Remove tax_query Completely
- How to access a query twice in different template files?
- Counter problem, infinite loop when post_per_page equals X
- Assigning a meta_query value based on regexp to wp_query fails
- Getting Taxonomy inside WP_Query Loop
- Nested tax_query that allows specified categories OR tags, but NOT other categories
- How to delete taxonomy term when a wordpress user is removed?
- Custom query based on meta key – Reduce three states to two in results?
- How to create a WordPress Post Filter that users can use to filter posts by year?
- Exclude category for main query and custom
- WP_Query custom query showing only 10 posts on all pages
- Not getting metavalue
- Ajax load more posts – WP_Query parameters not working
- How to display multiple custom fields with the same meta_key in an ascending order?
- Using the_post_thumbnail resets current loop item ID
- Meta_query with multiple keys and multiple values
- WordPress WP_Query make mysql time out
- Get authors by term id or slug
- Assign Json file to WP_Query
- How do I query for posts by partial meta key?
- WP Query to have sticky posts first, with pagination and having a joint ‘posts per page’ arg with main loop
- New WP_Query calls Pre_get_posts filter twice
- Multisite wp_query & switch_to_blog issue
- How to increase load time of an archive/search page (WP_Query)
- Issue with front page navigation after upgrading to 3.4
- Ordering posts by an array
- Prevent author bio page from showing in search results
- Changing the default wp_search_stopwords
- WP_Query array key / value pairs?
- Get posts from multiple tax terms
- WP_Query offset is returning post from prevois loop
- Tax query is not working!
- How To Keep Search Title the same on paged Results
- Does WP_Query ‘responds’ badly to empty arguments?
- Get next/prev image/attachment in time with date query
- Reordering content using a meta value
- Adding query parameter to archive page returns 404
- Optimising WP_Query with ACF Fields
- WordPress AJAX Request returns 400
- Using wpdb prepare with a variable, turns it into a big string
- SQL to join u3g_users & u3g_meta_value with repeating data
- WP_Query no result if keyword contains number
- WP_QUERY order posts by two combined meta_value dates
- Order by value of Custom Field using url string
- update_post_meta performance in a loop woocommerce
- How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
- ACF: using two loops, the_field returns field content from another loop
- query_posts() doesn’t seem to be called in my page
- WP_Query returns empty if meta_query has more than 7 values
- How to get several fields from wp_query?
- Pagination not working with WP_Query (creates links but no page)
- WP Query posts__in not working with array
- query_posts with sorting on a custom datestamp
- Conditionals in WP_Query
- Query Posts by date range with fixed beginning and end
- query by meta value then date and not empty meta value
- Is it possible to use WP Query to orderby custom meta value and custom taxonomy?
- Display all custom meta field values from the database using ACF Repeater
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Get posts using multiple values from ACF checkbox as meta query wordpress
- How to save the results of a query as a php file for an autocomplete search bar
- Why ignore_sticky_posts argument is in sticky post query?