Declare $my_post_id
as global in your code. Declare $my_post_id
as global in the-post.php
template. Your code:
global $my_post_id;
$my_post = array(
'post_type' => 'theposttt',
'post_title' => 'test',
'post_content' => '',
'post_status' => 'publish',
'post_author' => 1
);
$my_post_id = wp_insert_post($my_post);
if(is_wp_error($my_post_id))
$my_post_id = 0;
Now, you can use $my_post_id
in the-post.php
template. Possible values: 0 ( failure ), post id ( success ).
Related Posts:
- How to update custom fields using the wp_insert_post() function?
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- New Plugin Review
- Use template for posts with a particular category grandparent
- Query all posts of a custom taxonomy term
- Can’t get wp_insert_post to work
- Get post id in a function when edit/add a post
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Which PHP page is the Default Posts Page
- Function works everywhere, how to keep it to execute when creating a new post
- Pagination on Custom Post
- How to use mysql LIKE with wpdb?
- Reading settings in the home page precisely home.php
- Add new post in existing categories using wp_insert_post
- remove specificly the last tag in all posts
- How to Send Pingbacks for all Posts in WordPress?
- posts_per_page displays only 2 posts instead of 4 posts
- Send POST request to Flask app from functions.php file
- How to center all text body in single.php at once?
- Getting page / post URL on publish and / or update
- Displaying POST content with HTML tags and all
- Using Tag Groups: Displaying groups and adjacent tags of current post
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- insert thumbnail image from php script
- Can’t put a hyperlink on Featured Post’s Image
- Weird Behaviour: Not all WordPress Posts appearing
- Published custom posts missing
- WordPress get_post_meta issue
- Insert wordpress tags below posts via functions.php
- Trying to see if page is category or single and displaying title with appropriate heading tag
- How to modify this function to exclude also the post belonging to a specific category?
- How to display the date under the post title?
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- Add multiple HTML attributes to an Elementor button
- WooCommerce: write featured image dimensions to custom fields in product’
- How do I get a function to work in single.php
- transition_post_status hook, works – but not if the post is new
- How to change post date and post time in WordPress automatically with a function
- Removing unneccessary p-tags (Not every p)
- How to remove the excerpt in the Dzonia Lite theme
- comments_number display outside specified span
- Choose To Display Post Views With An Options Panel
- Prevent Data Resubmission On Page refresh
- Set WordPress Default Template
- Remove posts after a given amount of time
- Shortcode content filter?
- Automatically add custom CSS to new posts using a category template
- Randomise upload filenames (or another solution to hide the original image URL from theft?)
- How do I display a user’s previous orders as a select box option on a product?
- How Display Posts on category
- Using file_get_contents with Gravity Forms uploads folder to create images in the media library returning false
- Hide wordpress field if data is empty in post!
- allow subscribers to see private posts without plug in
- Replace word in “the_content” only for index.php
- How do you add customer capability after Woocommerce purchase?
- How to get specific image in media library with php
- Function set default image when image not present
- How can I use wp_query to show all product data using just the products ID?
- Custom location for attached images
- WooCommerce – Reset quantity input field when variation changes
- get current product name in functions.php
- Retrieving Author ID in wp-admin area
- Get first URL from post content
- Setting custom canonical urls
- Handling Body class based on Template
- Trigger popup in a php if/else statement
- Setting a cookie upon specific URL visit
- Get_avatar filter?
- Can’t get page content in WordPress
- WordPress child theme fails to override parent navigation menu in /inc/structure/header.php
- Way to querry data (tags) from a wordpress database?
- get post based on category chosen in drop down – The ajax method
- Adding Default Settings to Theme My Login plugin
- Image as Sales Badge
- how to make separate field in wordpress user_data_
- Getting a specific post values to another div or modal
- Function not working at one place
- jQuery not defined
- Displaying the Month and Year that a page was Created?
- Changing custom logo link
- Add a class to the anchor tag on HTML5 gallery
- Trying to add attribute to my posts’ featured image
- Conditional Header in wordpress
- Remove meta description on certain pages
- Menu — How to add “current-menu-grand-ancestor” css class
- Use menu link or onClick to set a variable
- Swapping wp_dropdown_categories function with wp_category_checklist
- functions.php is being included twice, creating PHP fatal errors
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- Automatically remove a canceled order in Woocommerce
- Display fields as values in array from external SQL DB
- Only Show Link If div Exists
- Displaying the last post on static homepage
- How to put a variable in a instance in the widget
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Why not yield/iterable in posts interface?
- Trying to establish connection to External Database
- add_action shortcut?
- Passing the custom field values in the wp_get_current_user array function
- Best practice for migration friendly images in posts/pages?