0
  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"
id="input-title"/></label><br>   
<label>Catogries:-</label><br><label > <?php
wp_dropdown_categories('orderby=name&hide_empty=0&exclude=1&hierarchical=1');
?> </label><br>

    <label>Content:-</label><br><label><textarea  class="form-control"  rows="5" name="post_content" cols="66"
id="text-desc"></textarea> 
    <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

1 Answer 1

1

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

4
  • 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 Apr 25, 2018 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 Apr 25, 2018 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. Apr 27, 2018 at 1:20
  • Yes Yes......but dynamicaly Apr 27, 2018 at 6:47

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