Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do i need to register post type before inserting value under specific post type in wordpress?

Tags:

php

wordpress

I want to record email address of user who are submitting their email address from userend.

<?php
$my_post = array(
          'post_title'    => 'Subscribed Email',
          'post_content'  => '[email protected]',
          'post_status'   => 'publish',
          'post_author'   => 1,
          'post_type'     => 'subscription',
        );
$insertPost=wp_insert_post( $my_post );
?>

Here do i need to register subscription as a post type at first? Or it does not matter if i directly insert it with out registering post type?I do not need to show it on admin panel.

like image 454
salin kunwar Avatar asked Nov 26 '25 22:11

salin kunwar


1 Answers

Your code will insert custom post type entry into the database even if you do not register custom post type before, but without registering custom post type you will not have permalink structure associated with CPT and will not be able to access it via url and you will not have an admin interface.

like image 136
Nick Surmanidze Avatar answered Nov 28 '25 17:11

Nick Surmanidze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!