posts with status other than 'published' not showing in backend
-
I encountered a very odd situation here. I have a custom post type and created a form for users to submit content. Each form-submitted post is being set to ‘draft’ but in the backend those posts are not showing.
I do know that the posts are being saved because they are in the database and the backend even displays the number of posts with status ‘draft’.
When I hit “All Posts (42)” only the published ones are listed. When I hit “Drafts (12)” it says “no posts found”.
Does anyone have a clue about what COULD be the problem here?
-
Hi,
Can you share your form code, also share code which are showing custom
posts in backend.This is my page template code which contains the form and the function behind it:
<?php /* Template Name: Submit Business Listing */ ?> <?php global $cfs; // check if form was successfully submitted if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) { if (isset ($_POST['title']) ) { $title = $_POST['title']; } else { echo 'Message text...'; $hasError = true; } if (isset ($_POST['address']) && isset ($_POST['zipcode']) && isset($_POST['cities']) ) { $address = $_POST['address']; $zip = $_POST['zipcode']; $city = trim($_POST['cities']); } else { echo 'Message text...'; $hasError = true; } if (isset ($_POST['sendername']) && isset ($_POST['sendermail']) ) { $sendername = $_POST['sendername']; $sendermail = $_POST['sendermail']; } else { echo 'Message text...'; $hasError = true; } if (isset ($_POST['cat']) ) { $branch = $_POST['cat']; } else { echo 'Message text...'; $hasError = true; } // setup new post data $term = get_term( $city, 'cities' ); $post = array( 'post_title' => $title, 'post_content' => ' ', 'post_status' => 'Draft', 'post_type' => 'my-custom-post-type', 'tax_input' => array($branch, $ort) ); $new_post_id = wp_insert_post($post); // if no error, send email if(!isset($hasError)) { $editLink = '<a href="'.get_edit_post_link( $new_post_id ).'">Prüfen und Freischalten</a>'; $deleteLink = '<a href="'.get_delete_post_link( $new_post_id ).'">L?schen</a>'; $admin_email = get_settings('admin_email'); $emailTo = $admin_email; $subject = __( 'Subject Text: ').$title; $body = __( "Body text..."); $headers = __( 'From: ') . "[email protected]" . "\r\n" . __( 'Reply-To: ') . $senderemail; add_filter('wp_mail_content_type',create_function('', 'return "text/html"; ')); wp_mail($emailTo, $subject, $body, $headers); $emailSent = true; } // redirect to success-page $link = get_permalink( 66 ); wp_redirect( $link ); $field_data = array ( 'additional-title' => $_POST['title-addition'] . ' ' . $_POST['title-addition-2'] . ' ', 'address' => $_POST['address'], 'zipcode' => $_POST['zipcode'] . ' ' . $term->name . ' ', 'phone' => $_POST['senderphone-pre'] . ' ' . $_POST['senderphone'] . ' ' ); $post_data = array('ID' => $new_post_id); $cfs->save($field_data, $post_data); wp_set_post_terms($new_post_id,$branch,'branches',true); wp_set_post_terms($new_post_id,$ort,'cities',true); } do_action('wp_insert_post', 'wp_insert_post'); ?> <?php get_header(); ?> <div id="maincol"> <?php if( have_posts() ) : the_post(); ?> <article id="page-<?php the_ID(); ?>" class="page"> <header class="page-header"> <h1 class="page-title"><?php the_title(); ?></h1> </header> <?php the_content(); ?> </article> <?php endif; ?> <form id="new_post" name="new_post" class="post_entry" method="post" enctype="multipart/form-data"> <h4>Business Infomation</h4> <p> <label for="title">Title</label><br /> <input type="text" id="title" value="" tabindex="1" size="20" name="title" class="senderinfo" /> </p> <p> <label for="title-addition">Addition</label><br /> <input type="text" id="title-addition" value="" tabindex="1" size="20" name="title-addition" class="senderinfo" /> </p> <p> <input type="text" id="title-addition-2" value="" tabindex="1" size="20" name="title-addition-2" class="senderinfo" /> </p> <p id="floated"> <label for="branchen">Branches:</label><br /> <?php $select_cats = wp_dropdown_categories( array( 'echo' => 0, 'taxonomy' => 'branches', 'hide_empty' => 0 ) ); $select_cats = str_replace( "name='cat' id=", "name='cat[]' multiple='multiple' size='8' class='senderinfo' id=", $select_cats ); echo $select_cats; ?> </p> <p> <label for="address">Address</label><br /> <input type="text" id="address" value="" tabindex="1" size="37" name="address" class="senderinfo" /> </p> <p> <label for="plz">Zipcode / City</label><br /> <input type="text" id="zip" value="" tabindex="1" size="5" name="zip" class="senderinfo" /> <?php wp_dropdown_categories('taxonomy=cities&hierarchical=1&hide_empty=0&orderby=name&order=asc&name=gemeinden&show_option_none=Choose') ?></p> </p> <p> <label for="senderphone">Phone</label><br /> <input type="text" id="senderphone-pre" value="" tabindex="1" size="8" name="senderphone-pre" class="senderinfo" /> <input type="text" id="senderphone" value="" tabindex="1" size="24" name="senderphone" class="senderinfo" /> </p> <button type="submit" id="submit" class="btn-success" name="submit"> <span class="flaticon-send"></span> Send data </button> <input type="hidden" name="action" value="new-post" /> <input type="hidden" name="post_type" id="post_type" value="domande" /> <?php wp_nonce_field( 'new-post' ); ?> </form> </div><!-- maincol--> <aside class="sidebar" id="sidebar-main"> <?php get_sidebar(); ?> </aside> <div class="clear"></div> <?php get_footer(); ?>
I dont’ quite understand what you mean by code that shows custom posts in backend. What I meant is when you click e.g. “Posts” in the admin panel, you see a list of your posts and you can choose if you want to see all of them or only the published ones, the drafts, the ones in the trash etc. That’s the point: it says “Drafts (12)” but with that option chosen, instead of displaying my drafts it says “no posts found”.
As given ‘my-custom-post-type’ in the given code is the custom post type which you will need to pass as post_type, this post type will shows in backend for that you must create custom post type for the backend please review this link (https://codex.www.ads-software.com/Function_Reference/register_post_type)
$post = array(
‘post_title’ => $title,
‘post_content’ => ‘ ‘,
‘post_status’ => ‘Draft’,
‘post_type’ => ‘my-custom-post-type’,
‘tax_input’ => array($branch, $ort)
);
There are some plugins are available for creating custom post type : (https://www.ads-software.com/plugins/custom-post-type-ui/)The given code is fine and you just need to create custom post type in backend these posts will automatically in shows after that.
Sushil,
I have already registered that custom post type along with custom taxonomies and it works fine – I can publish posts from the backend and all but, though, those posts submitted by the above form won’t display as drafts properly whereas those posts I submit via form are not being shown as drafts in the backend.
Same issue when directly moving those post drafts to the trash. It says “Trash (1)” and if you choose that option it says “no post found” again.
Please confirm that ‘post_type’ => ‘my-custom-post-type’ given in the code(‘my-custom-post-type’) is same as when you see all custom posts in backend please check post_type in URL (/edit.php?post_type=my-custom-post-type) both must be same.
I need to review your backend or files to resolve this issue.
Do you have staging server where i can review this??
- The topic ‘posts with status other than 'published' not showing in backend’ is closed to new replies.