1

I am hope for your help

I have a custom post-type on my site - "Campaigns", I want to make that the user can on the page /my-account/campaigns was able to see the list of his posts, delete / edit them, and create new

I Created a new endpoint, add this edpoint to account menu and include template

Thank!

UPDATE:

I have solution for display list of post

<?php

if (!class_exists('list_user_posts')) {

class list_user_posts
{
    function __construct($args = array())
    {
        add_shortcode('user_posts', array($this,list_user_posts));
    }

    public function list_user_posts($attr = array(), $content = null)
    {
        extract(shortcode_atts(array(
            'post_type' => 'post',
            'number' => 10,
        ), $attr));

        if (!is_user_logged_in()){
            return sprintf(__('You Need to <a href="%s">Login</a> to see your posts'),wp_login_url(get_permalink()));
        }

        $pagenum = isset( $_GET['pagenum'] ) ? intval( $_GET['pagenum'] ) : 1;

        $args = array(
            'author' => get_current_user_id(), //this makes the query pull post form the current user only
            'post_status' => array('draft', 'future', 'pending', 'publish'),
            'post_type' => $post_type,
            'posts_per_page' => $number,
            'paged' => $pagenum
        );
        $user_posts = new WP_Query( $args );

        $retVal = '';
        if ( $user_posts->have_posts() ) {

            $retVal = '
                <div class="row">
                    <div class="col-md-6">'.__( 'Title', 'lup' ).'</div>
                    <div class="col-md-3">'.__( 'Status', 'lup' ).'</div>
                    <div class="col-md-3">'.__( 'Actions', 'lup' ).'</div>
                </div>';
            global $post;
            $temp = $post;
            while ($user_posts->have_posts()) {
                $user_posts->the_post();
                $title = $post->post_title;
                $link = '<a href="' . get_permalink() . '" title="' . sprintf(esc_attr__('Permalink to %s', 'lup'), the_title_attribute('echo=0')) . '" rel="bookmark">' . $title . '</a>';
                $retVal .=
                    '<div class="row">
                        <div class="col-md-6">
                            ' . (in_array($post->post_status, array('draft', 'future', 'pending')) ? $title : $link) . '
                        </div>
                        <div class="col-md-3">
                            ' . $post->post_status . '
                        </div>
                        <div class="col-md-3">
                            <a href="LINK_TO_YOUR_EDIT_PAGE"><span style="color: green;">' . __('Edit', 'lup') . '</span></a>
                            <a href="LINK TO YOUR DELETE PAGE"><span style="color: red;">' . __('Delete', 'lup') . '</span></a>
                        </div>
                    </div>';
            }

            if ($user_posts->found_posts > $number ){
                $pagination = paginate_links( array(
                        'base' => add_query_arg( 'pagenum', '%#%' ),
                        'format' => '',
                        'prev_text' => __( '&laquo;', 'lup' ),
                        'next_text' => __( '&raquo;', 'lup' ),
                        'total' => $user_posts->max_num_pages,
                        'current' => $pagenum
                    )
                );
                if ( $pagination ) {
                    $retVal .= '<div class="pagination">'.$pagination .'</div>';
                }
            }
            return $retVal;
        }else{
            return  __("No Posts Found");
        }
    }

  }
}
new list_user_posts();   

Now, I need the button for "Create post" and edit/delete links

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.