WordPress.org

Ready to get started?Download WordPress

Forums

If post belong to author and if post in category x then show edit/delete (2 posts)

  1. qzha017
    Member
    Posted 1 year ago #

    Hi everyone I am trying to show an edit and delete button (frontend)in the single post based on 2 conditions.
    1.) is the current logged in user the author of the post AND
    2.) is the Post in the category 'X'

    if both conditions is met then display an edit and delete ink, if not then don't give the edit and delete link.

    <?php edit_post_link( __( 'edit',
     'twentyten' ), '<span class="edit-link">', '</span>' ); ?>

    the above snippet already checks for author of post (by theme default) so how do I add the category condition in it?

    is this conditional tag to use?
    <?php is_category( $category ); ?>

    I have tried it didn't work maybe I have done it wrong.

    Thanks everyone

  2. qzha017
    Member
    Posted 1 year ago #

    let me update my question and make it more clearer
    the following is in my loop-single.php

    <?php	global $current_user;
    	get_currentuserinfo();
     if ($post->post_author == $current_user->ID) { ?>
      <a onclick="return confirm('you sure you want to delete?')" href="<?php echo get_delete_post_link( $post->ID ) ?>">delete post</a>
    
    <?php } ?>

    I want to add the condition is this post in the category 7?
    I assume I use the <?php in_category( $category, $_post ) ?>
    But where and how do I add it?

    can anyone please help me out here

Topic Closed

This topic has been closed to new replies.

About this Topic