سؤال

I have three custom post types, each with around 5 taxonomies and 2 of the custom post types share two taxonomies.

I've just about got everything set up for posting from the front end other than the part of a dropdown to show the post_types.

As it is now front end posting works but, the urls are broken because they dont have the custom post type in them, i've searched all over and can find zero on listing custom post types... can it be done?

Regards Martin

edit: Just stumbled upon this over at codex,,

هل كانت مفيدة؟

المحلول

Sorry about that feels a bit weird answering ones own question, but here you go....

Firstly declare the variable: (customcategory)

global $userdata;

$errors = array();

$title      = trim($_POST['wpuf_post_title']);
$customcategory      = trim($_POST['customcategory']);
$content    = trim($_POST['wpuf_post_content']);
$tags       = wpuf_clean_tags($_POST['wpuf_post_tags']);
$cat        = trim($_POST['cat']);

Secondly the array for adding the post:

 if (!$errors) {
    $frontend_post = array(
            'post_title'    => $title,
            'post_content'  => $content,
            'post_status'   => $post_status,
            'post_author'   => $userdata->ID,
            'post_category'    =>    array($_POST['cat']),
            'post_type' => $customcategory,
            'tags_input'    => $tags
    );

    $post_id = wp_insert_post($frontend_post);

and finally create the dropdrown from the get_post_types function:

<?php 
          $args=array(
                     'public'   => true,
                     '_builtin' => false
                     ); 
                $output = 'names';
                $operator = 'and';
                $post_types=get_post_types($args,$output,$operator); 

          echo '<select name="customcategory">';
          foreach ($post_types  as $post_type ) {
          echo '<option value="'. $post_type.'">'. $post_type. '</option>';
}echo '</select>';
?>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى wordpress.stackexchange
scroll top