You should first run the wp_insert_post()
which will return the post ID. Then use that post ID to add your custom fields. Use add_post_meta()
to add the custom fields.
$post_id = wp_insert_post( $args );
add_post_meta( $post_id, 'longitude', $my_long );
add_post_meta( $post_id, 'latitude', $my_lat );
For image attachments, you can refer to this question: How to set featured image to custom post from outside programmatically
Related Posts:
- How can I programmatically save data into custom fields that contain serialized data?
- See if the email exists or not
- wordpress form processing to custom post type not working
- How can I remove the “Add New” button in my custom post type?
- How to display categories of my Custom Post Type?
- Inconsistent temporary 404s on whole install | PHP error with post-template.php
- Display a query with multiple post types and same relationship on a single page
- WordPress Custom Post Types with a page as a parent?
- Query menu_order custom post types
- Get post ID from wp_insert_post()
- Get Custom Taxonomy ID within loop
- Custom post status not working
- WP insert post and custom taxonomy
- List page for custom post type?
- Search that will look in custom field, post title and post content
- Load custom posts with same tag as page
- Get custom post type by category in a page template
- Is it possible to create an “export to PDF” option?
- using the_permalink to echo an href into a
- Date archives for custom post type
- Not Able to Insert Taxonomy Term Using wp_insert_post()
- If featured image doesn’t exist, show post content
- How can I add dropdown widget/box to admin post page?
- Categories under custom post types doesn’t show properly
- How to get a list of term names of the custom post type im currently on in single.php
- Meta Query “IN” doesn’t work with ACF checkbox filter
- is_singular won’t call my functions?
- Include images from pages in wp search.php results in default wp search
- How I upload, save and set a featured image from my frontend?
- How do I redirect all 404 errors of a specific post type to another URL?
- Ajax filter with custom taxonomies
- List events by month
- Filter posts with ajax form and checkboxes
- Trying to save custom post type from frontend partially working
- how to use two permalinks for one custom post type
- Clean URL permalink for custom post type
- Using ‘strtotime’ function to convert a custom-meta-box to a date-stamp
- Get custom post type REST API not working
- How to save the checked boxes?
- Custom post type loops with different page templates
- wp_insert_post custom taxonomy
- Assign category to front end post
- WP insert post PHP function dynamically generated Custom Fields
- Limit Authors to their Own Posts on front-end excluding admins
- How to get only one category of custom post type?
- Adding a span when custom post type is updated
- What hook should be used to programmatically create a post only when master post is updated?
- Inserting data into `post meta` table?
- Error after deleting Custom Post Type with a function (no trash used)
- WordPress is executing URL in code when called via wp_mail()
- Get all taxonomies for all post types
- How to redirect all pages of a custom post type [duplicate]
- Row actions not showing? Why?
- Displaying custom post type on front page
- Append taxonomy terms as class names in markup?
- Custom Post Type .current-menu-item not applying on Custom Post Type Archive Page
- How do you output custom code between posts in the loop?
- Show ACF field from custom taxonomy and display on the single template
- How to allow “Add New” capability of CPT when links to its UI are placed as a submenu?
- Change message given when deleting post from custom post type
- Display children and grandchildren of a custom post type
- How to append element after thumbnail
- wordpress custom post type remove duplicate menu item
- Using WPAlchemy metabox values in another metabox
- is_page_template not working as expected
- List terms from Custom Taxonomy
- WordPress tax_input only if logged in
- Programmatically adding posts
- WP_Query search posts by custom post type and custom taxonomy
- Dynamic Custom Post Type Plugin
- Order WordPress Custom Taxonomy Pages & Pagination Not Working
- I am having a problem with form updating/editing WordPress post on the frontend
- How to filter out post type meta?
- How to make in WordPress admin panel sortable column for the custom field, that count the number of page impressions?
- Display custom field of specific post where post title matches variable
- Conditional to modify query results
- Loop through posts of a custom-post-type (event) and create .ics (iCal) file?
- Output custom post shortcode. Help spot the error.
- How to count custom post types with conditional operators
- Is it possible to create a post using a metabox?
- WP_Query is printing out only one post when posts_per_page is set to multiple
- WP Query to displaying date and posts for that date?
- GravityForm: Populate Dropdown with custom post type [closed]
- Return array of categories to php function for current post
- Link users to a custom post type
- Create a random unique 6 digit number as custom field for custom post type
- How to output wordpress custom tags separated by comma?
- Loading all files within a directory
- Blog page showing same content as homepage
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- How Can I Set the Post Author of a Post I Just Created With PHP?
- Using several custom fields as custom post title
- Custom Post Type without an archive page
- Get rewrite slug of custom post type in template
- Show Different Header on a Specific Post ID
- Get Post Primary Category
- Weird problem happening with custom taxonmy when creating/updating posts
- A good strategy to print custom posts (offer) that are checked inside the metabox of a post?
- How to auto increment post title & post slug field?
- Having issue on Loading Meta Data From CSV to CPT