Support » Plugins » [Plugin: Post From Site] Post to Custom Post Type

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi xevo – did you get a solution for this? I also need some sort of code to be executed either from within a template or from a widget, which takes users directly to Create New ‘Product’ (example) – where ‘product’is the name of my custom post. I have looked at this solution for linking to admin: – I figure I can then customise the admin to look like my site. But I don’t know the code to link specifically to the Create New Custom Post page. I need to change this:

    <?php echo get_option('home'); ?>/wp-admin/post-new.php">

    to link to ‘write new Product’.

    Any thoughts anyone? Thanks

    Does this not work, drmunden?

    <?php echo get_option('home'); ?>/wp-admin/post-new.php?post_type=product">

    I was able to post to custom post type by editing the pfs-submit.php file (line 115) – $postarr[‘post_type’] = ‘post’; (obv change ‘post’ to your custom post type.

    I’ve been using this plugin for a few days now and made a couple customizations along these lines you all might find useful. I’m using this for a front-end form which visitors can use to submit questions to the site admin. I’ve created a custom post type of ‘question’ and a custom taxonomy for ‘status’,

    I previously added comments and custom code to this file so unfortunately I’m not sure what the exact lines are for everyone else- sorry for the confusion- but if you Ctrl+F you will find this section easily.

    $postarr = array();
    			$postarr['post_title'] = $title;
    			$postarr['post_content'] = $content;
    			$postarr['comment_status'] = $pfs_options['pfs_comment_status'];
    			$postarr['post_status'] = $pfs_options['pfs_post_status'];
    			$postarr['post_author'] = $user_ID;
    			$postarr['post_category'] = $categories;
    			$postarr['tags_input'] = implode(',',$tags);
    			$postarr['post_type'] = 'askmark';
    			//echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">".print_r($postarr, true)."</pre>\n";
    			$post_id = wp_insert_post($postarr);
    			if (0 == $post_id) {
    				$result['error'] = __("Unable to insert post- unknown error.",'pfs_domain');
    			} else {
    				$result['success'] = __("Thanks for sending in your question for Mark!  We hope to answer as many of these as possible here on the site so please check back soon!  <br /><br /> <a href=\"\">Click here to see previous questions.</a>",'pfs_domain');
    				$result['post'] = $post_id;
    				//Added this section to write form data to custom meta boxes and custom taxonomy for post -custom code
    				add_post_meta($post_id, 'meta_askmark_name', $title);
    				add_post_meta($post_id, 'meta_askmark_town', $town);
    				wp_set_object_terms( $post_id, 'New', 'status', false); //set the Ask Mark status to New- end added code
    		} else {
    			//Custom randomized error messages -custom code
    			 $randomvar = rand(1,3); // Random var becomes a random number from 1 to 3
    			 if ($randomvar == 1) $result['error'] = __("It looks like you either forgot to put in your name our your question!",'pfs_domain');
    			 if ($randomvar == 2) $result['error'] = __("Hey, it looks like you forgot to enter either your name or your question!",'pfs_domain');
    			 if ($randomvar == 3) $result['error'] = __("Wait!  Don't forget to enter your name and a question for Mark!",'pfs_domain');
    	//removed login requirement -custom code
    	return $result;


    In the last $postarr line I set the custom post type to ‘question’ which is easy enough. Then I decided I want to customize the success message so I edited the output for $result[‘success’]- simply add your own HTML (but remember that since you are inside an echo function, put a \ before any quotes(“) in your HTML.

    Separately I’ve created custom fields for Questions: one for the askers name and another for their hometown (Previously I also added a Hometown field to the PostfromSite form- saves as the variable $town). So here I add that data to the post with add_post_meta and then I use wp_set_object_terms to set the value of my custom taxonomy (‘status’) to New.

    This way, when a site admin logs in, they go to the Questions section of the admin panel and see all the New questions that need to be replied to.

    Below all of this is just some fun I had with error messages- randomly pick a number between 1-3 and then cycle through these error messages depending on the random number selected… an easy way to add a bit of uniqueness.

    This might be helpful to some people looking to customize the form- I try and avoid editing plugin code when I can but I just needed to get this done this week.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Post From Site] Post to Custom Post Type’ is closed to new replies.