Try doing this:
$insert_post = wp_insert_post(array(
'post_author'=>1,
'post_date'=>date('Y-m-d H:i:s'),
'post_date_gmt'=>date('Y-m-d H:i:s'),
'post_content'=>'',
'post_title'=>'',
'post_excerpt'=>'',
'post_status'=>'publish',
'comment_status'=>'closed',
'post_name'=>'',
'post_parent'=>0,
'post_type'=>'portfolio', // with 'portfolio' custom post type
'post_category'=>array($id),
));
if( $insert_post ) {
wp_set_object_terms( $insert_post, intval( $id ), 'galleries');
}
Using wp_set_object_terms
you can set the terms for the post in any taxonomy. The first argument is the ID of the post, the second argument is the ID or slug of the term, and the third is the name of the taxonomy. If you use an ID for the term, you must use intval()
otherwise it will create a term that is just a number.
Related Posts:
- How can I configure Docker for developing and deploying a custom theme?
- Where to store PHP files created by plugin / themes
- Custom theme sufficient or custom plugin neccessary for this feature set?
- How to create custom home page via plugin?
- Featured Image not showing in admin
- How Can I setup WP CLI on Windows development machine running AMPPS?
- WP_LOCALIZE_SCRIPT doesn’t work
- Are we allowed to use the Allman (BSD) indent style when coding WordPress plugins and themes?
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- Customizer: widget-synced triggers twice
- WordPress not working on localhost
- Applying OO patterns and principles to plugin development
- Widget HTML Display Problem
- Redirect to another page using contact form 7? [closed]
- Custom entity search and display
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- Why in this archive page that call query_posts() function show only the last 10 posts?
- Getting a WordPress Debug Strategy
- How to replace settings in WordPress plugin from a theme
- How to remove/replace current page template?
- How to determine which capability to use?
- Want to know how to reveal a WordPress theme, considering the theme name is hidden?
- Rename a folder via HTML POST request
- Metabox types list
- Rate limiting ajax requests in WordPress
- Determine if the current page, is being edited
- Managing Custom Designed Content
- Best practice: What belongs in theme and what in plugin for large eCommerce website
- Adding class to the parent of current-post-ancestor / current-menu-parent / current-post-parent
- Is Explicit Versioning a better alternative to Semantic Versioning for wordpress?
- Is there any other ways to replicating changes on live from staging without pushing from git
- ajaxurl not defined on front end
- How to include jQuery and JavaScript files correctly?
- How to post data to same page in wordpress
- Include a external PHP file into a WordPress Custom Template
- Understanding WordPress functions’ naming conventions
- How to remove hardcoded characters from playlists?
- Allowing for multiple template views on the Gallery Settings page when using the Visual Editor
- Has anyone managed to integrate the wp_editor inside a widget?
- Using Primary Color in Plugin Block
- Show a user their recently viewed posts
- When is it appropriate to put functions on page template vs. functions.php?
- Add new user and add meta at once
- How to Display Custom Post Type’s Gallery (images ) in Through WP_Query
- Error : “Updating failed: The response is not a valid JSON response” with custom shortcode
- What’s the better way to add an inline script?
- Delete a specific item menu when I deactivate my plugin
- Backslashes being stripped from CSS
- Finding the paragraphs in content
- Order properties should not be accessed directly
- How to avoid loading same script twice?
- Can I individually style items in the backend widget list?
- Finding posts containing matching array elements in a meta field usign WP_Query
- Executing a function upon webhook calling wordpress
- How to Create Custom HTML Tag on Editor in `Text(HTML)` mode
- how to use hook deleted_user into custom function to delete user from custom table
- Where to store the name of a custom table?
- How to filter users list on user_status field with get_users()
- Can Page Templates be Applied to Archive and Post Templates?
- Clearing caches on plugin uninstall
- Is there some way to provide the user a list of existing content in a CPT
- Change the look and feel of admin pages
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- What is the proper method of using global $post?
- How to change title tag at page after loaded post?
- WordPress custom taxonomy check box to dropdown
- How to modify files inside wp-includes directory in wordpress
- zip unzip attachments in wordpress
- Create Widget or Enable Shortcodes in Sidebar
- Conditional Generation of Image Sizes using add_image_size
- WP Still Generating 150×150 Thumbnail Size Even After Un-Setting Small Size in Functions.php
- Does WordPress default CSS have Grids?
- Why is it important to check for isset and is_array before checking in_array in this example?
- How to resize WordPress images on upload to specific height and width without cropping it
- Toolbar Hidden in a Virtual Page
- Adding Permalink to Slides with ‘Simple Nivo Slider’ plugin?
- rewrite_rules problem
- Why does website stretch and white space on load? [duplicate]
- How to make premium plugin? I want to limit it until verification
- How to hide/remvoe unnecessary field/section in post edit section ( Dashboard )
- Does hooking into a plugin action / filter override the plugin’s function for that hook?
- Scripts/styles not loading on cloned WP Site when logged in
- How to prevent users from deleting their accounts?
- Having issue on Loading Meta Data From CSV to CPT
- WordPress delete mysql rows with string
- Is it possible to modify an Elated plugin portfolio-list template in such a way that it will not conflict with future plugin updates?
- Woocommerce Custom Checkout
- Where can I find the declaration of `$_wp_theme_features`?
- Display tab title as ‘blog tagline | blog title’
- Theming Custom Plugin Page
- variable created in page.php is null inside of header.php
- How do I store a custom dataset in WordPress to best take advantage of API?
- Create and style menu
- How to create post comparison in wordpress
- Custom plugin not appearing
- how to catch a data from a array in WordPress
- How react js and other Javascript Technologies works on WordPress plugin?
- Can I log the searches that are returning 404 in the DB?
- Remove Gutenberg Buttons Block