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
- Inconsistent temporary 404s on whole install | PHP error with post-template.php
- Search that will look in custom field, post title and post content
- Load custom posts with same tag as page
- using the_permalink to echo an href into a
- Filter posts with ajax form and checkboxes
- Get custom post type REST API not working
- Get all taxonomies for all post types
- Custom Post Type .current-menu-item not applying on Custom Post Type Archive Page
- How to allow “Add New” capability of CPT when links to its UI are placed as a submenu?
- wordpress custom post type remove duplicate menu item
- List terms from Custom Taxonomy
- WP_Query search posts by custom post type and custom taxonomy
- Dynamic Custom Post Type Plugin
- How to filter out post type meta?
- Loop through posts of a custom-post-type (event) and create .ics (iCal) file?
- How to count custom post types with conditional operators
- Is it possible to create a post using a metabox?
- How Can I Set the Post Author of a Post I Just Created With PHP?
- Using wordpress template tags within an array
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- Getting the URL of the parent page
- get_posts of Custom Post Type AND Custom Taxonomy
- Get posts from a custom post type by child categories of a parent category
- If post has custom field then display css-class
- Replace text in post from cvs
- Get parent categories of custom post type
- Query & Order posts by custom fields
- Custom Tag Description unable to display just below and outside of the Loop
- Can one create multiple Custom Post Types with a for loop?
- How to Upload CSV Data into Custom Post Type Data with Metabox programmatically
- How to add custom field to view-edit post type page
- Static apple-app-site-association file with wordpress
- search suggest – filter post type
- Breaking up CPT output into two columns
- Configuring a meta query with multiple post types that have the same relationship on a single page
- how to echo meta tag in header using php
- Trying to get custom post of a custom taxonomy
- PHP question: how to combine syntax?
- Add first letter of titles to array, then compare arrays
- How do I add custom HTML to the content of an archive page’s posts?
- widget_posts_args not using the number of posts in widget
- How To Post WordPress Custom Post Types to Twitter via IFTTT
- Undefined $post in wp_query
- WordPress hook which triggers on post import
- Custom post type and custom taxonomy 404 on page 2
- Show current user posts in custom post type query
- Importing JSON feed giving Notice: Array to string conversion error
- List latest post out of 2 custom post types
- insert image with custom post type
- Sets post_parent in custom post type posts automatically based on cpt->page name
- Show the categories the current post has
- Fetch data from two custom post types and create multidimensional array for output to html table
- Create a Dropdown Selector and Redirect for a Custom Taxonomy in WordPress?
- Create an user checklist system for a course plateform using ACF Pro and ACF Extended
- How to display “Trash” in my custom post type?
- How to get the custom post data using post id in WordPress?
- set object terms after some some time of published post – functions.php
- Why is my custom post content only viewable when signed into WordPress?
- On saving Post My permalink is updated and category is removed automatically which cause the 404
- Pagination not working in custom post type. Help
- wp_insert_post from XML feed only inserting first post
- How to add specific terms in a custom post type?
- Sending current featured image to email
- Plugin Development using classes – Public & Private Callbacks
- Limit custom post type to the authors only on front-end!
- WP_Query – How To Query Only Custom Posts With No Children of Their Own?
- programmatically generated custom post type is created more than once
- Dynamic page for nav items used as filters
- How to use posts as tabs in a custom page?
- wp_insert_post deleting previous post custom meta
- Accessing download link from the loop with WP Download Manager Pro
- Create posts inside CPT post
- Taxonomies are not showing in the category dropdown
- How to use POST method using custom wordpress button?
- Combine multiple separate lists into one
- News post with multiple permalinks? When opened from different page
- Custom Taxonomy – fields
- WordPress trying to query two custom types to get child from the parent
- wp_insert_post() creates duplicates with ‘post_status’ => ‘publish’
- Print post category name from a custom post type wordpress
- CPT post doesnt shows tags and category on backend admin page
- How to make sure, that only the selected post is changing?
- Create 2-layered dropdown menus for custom taxonomy and custom post type
- Get month and day from a Date Picker custom field
- Show Custom Post Type taxonomy term that matches custom field
- Select Menu for Custom post Type does not save
- is_singular won’t call my functions?
- Cant we use a PHP file directly like myhome.com/some.php?
- Is this the correct way to add post-slug input field?
- Inserting two categories
- After wp_insert_post() custom post type does not show in the admin
- Comments are not working on Custom Post Type
- Add Category names to post lists of custom post type
- Send email on creation of custom post type and use get_post_meta()
- add_rewrite_rule not working with custom post type
- Just the First Metabox what saves the data!
- Using wp_insert_post to create custom posts with ACF image field