0
votes

I am submitting a custom post type post from front end wordpress with pending status. I am trying to retrieve the pending post in the front end but it was not showing. I checked the same in admin portal, the pending post is showing there. 1. Able to post the custom post type with pending status using the below code. 2. Not able to show the pending post in front end but it was showing in admin portal pending posts. 3. If i post new post or save post as pending in admin portal and that post was showing in front end pending post listing. 4. The below code was working in local server but not working in client server.

Even i have checked the wordpress database, Trying one pending post from front end and admin portal, "posts" table showing the same entry columns. I am unable to find the difference in the database.

// Below code for inserting the post with pending status
$post = array(
        'post_title'    => $_POST['event-name'],
        'post_content'    => $_POST['event-description'],
    'post_date_gmt' =>  date("Y-m-d h:i:sa"),
        'post_status'   => array('pending'),
        'post_type'     => 'events', 
        'meta_input' => array(
            'custom_name' => $_POST['your-name'],
            'custom_phone' => $_POST['your-phone'],
            'custom_email' => $_POST['your-email']
        )
    );

// Below code for retrieving the pending post 
$args = array(
    'post_type'   => 'events',
    'post_status'   => array('pending'),
    'post_per_page' => 10,
    'order'          => 'desc'
   );

I checked through the wp_debug true, it was not throwing any type of errors. Expected output, front end page should show the pending post.

If any one have idea how to proceed this further, I am struck with this.

2
couple of points, 1) It's posts_per_page not post_per_page 2) wp_debug_display must also be defined as true to show errors. Neither of these would stop there query working though. Have you correctly defined the events post_type?andrew

2 Answers

0
votes

First make sure:define( 'WP_DEBUG', true );And then

$post = array(
        'post_title'    => $_POST['event-name'],
        'post_content'    => $_POST['event-description'],
    'post_date_gmt' =>  date("Y-m-d h:i:sa"),
        'post_status'   => array('pending'),
        'post_type'     => 'events', 

    'meta_input' => array(
            'custom_name' => $_POST['your-name'],
            'custom_phone' => $_POST['your-phone'],
            'custom_email' => $_POST['your-email']
        )
    );

// Below code for retrieving the pending post 
$args = array(
    'post_type'   => 'events',
    'post_status'   => array('pending'),
    'posts_per_page' => 10,
    'order'          => 'desc'
   );
0
votes

If you set post status in "pending" but this post status saves as the draft, can you please add one post using the form and check in the DB which status store in DB. See Post tabel in DB