1. Here my Code
<?php if(isset($_POST['new_post']) == '1') {
    $post_title = $_POST['post_title'];
    $post_category = $_POST['cat'];
    $post_content = $_POST['post_content'];
    $parent = get_the_tags($post_category);;

    $new_post = array(
          'ID' => '',
          'post_author' => $user->ID, 
          'post_category' => array($parent,$post_category),
          'post_type' => 'currencies',
          'post_content' => $post_content, 
          'post_title' => $post_title,
          'post_status' => 'publish'

    $post_id = wp_insert_post($new_post); print_r($post_id);
    // This will redirect you to the newly created post
    $post = get_post($post_id);    echo "Done";
    }       ?>   

<h1fhsdfh</h1> <form method="post" action=""> 
    <label>Post-Title:-</label><br><label><input type="text"  class="form-control"  name="post_title" size="45"
<label>Catogries:-</label><br><label > <?php
?> </label><br>

    <label>Content:-</label><br><label><textarea  class="form-control"  rows="5" name="post_content" cols="66"
    <input type="hidden" name="new_post" value="1"/> </label>
    <input class="subput round form-control"   type="submit" name="submit" value="Post"/> </form> <?php get_footer(); ?>

please see this image http://prntscr.com/j9toiz

closed as unclear what you're asking by Krzysiek Dróżdż, Nathan Johnson, Michael, Jacob Peattie, bosco May 21 '18 at 3:39

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


You can add custom columns in wp-admin to show parent category. It's here my code, you can try it (I tested with post_type is post (default)).

 // Add the custom columns to the post post type:
add_filter( 'manage_post_posts_columns', 'set_custom_edit_post_columns' );
function set_custom_edit_post_columns($columns) {
    $columns['parent_cat'] = __( 'Parent Category', 'storefront' );
    return $columns;

// Add the data to the custom columns for the post post type:
add_action( 'manage_post_posts_custom_column' , 'custom_post_column', 10, 2 );
function custom_post_column( $column, $post_id ) {
    if($column == 'parent_cat'){
        $terms = get_terms('category');
        foreach ($terms as $term) {
            if($term->parent == 0){
                echo $term->name;

Here is screenshot to view: http://nimb.ws/RpoV8W

  • Mr.Optical Thnx for rply but i have more than one parent catogory...and i want to display all that in dropdown..please if u have any idea then please let me know..i will b very thakful your's – phpdeveloper aegisbit Apr 25 '18 at 10:48
  • like i have 3 category and they also have 3 subcatgory each...Now i want a form prntscr.com/j9w9y2 and when i select a child of exit parent then in backend they will be checked like this prntscr.com/j9waod – phpdeveloper aegisbit Apr 25 '18 at 11:09
  • It's mean you want to show all categories in the dropdown and when you selected in front-end then checked is selected in the back-end. – Quang Apr 27 '18 at 1:20
  • Yes Yes......but dynamicaly – phpdeveloper aegisbit Apr 27 '18 at 6:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.