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
- Capture the Selected Radio Button Value between two files in wordpress theme
- How to determine if the current file is loaded in a plugin or in a theme?
- Is there any way to have Featured Text, as opposed to Featured Image?
- How to check if a stylesheet is already loaded?
- Show dialog box in TinyMCE plugin and use WordPress php functions in it
- Find source of notice / warning / errors efficiently
- Get the password key when using the wp_new_user_notification_email filter
- Problem with is_active_sidebar?
- Filter, or any way to dynamically change theme screenshot image?
- Finding the paragraphs in content
- Is Dreamweaver CS5 a serious choice for theme/plugin development?
- StackExchange clone using WordPress?
- What allows a template file from plugin to be copied in child theme and overridden?
- Sharing common functionality (functions, template parts) between plugins and themes?
- Order properties should not be accessed directly
- How to avoid loading same script twice?
- Can I individually style items in the backend widget list?
- WordPress security issue to output data from user input from theme option form
- WP_Query returns no results
- How do I alter the comment form ‘allowed tags’ text in a plugin?
- Finding posts containing matching array elements in a meta field usign WP_Query
- Change template dynamically
- How to deal with equal & similar arguments for a function?
- Should action callbacks start with a verb?
- PHP can I add line numbers to file_get_contents()
- Get rewrite slug of custom post type in template
- custom shortcode will not display the wrapped content
- Executing a function upon webhook calling wordpress
- Display content from custom post without modifying the single template
- WordPress add_admin_page not working even parameters are correct?
- How to Create Custom HTML Tag on Editor in `Text(HTML)` mode
- Is It Always a Best Practice to Decouple the Frontend from the Admin Area When Developing a WordPress Application?
- Displaying theme options in css
- Adding functions to hooks from within a class
- how to use hook deleted_user into custom function to delete user from custom table
- Disable The Events Calendar plugin from loading its scripts
- Can I change header.php of current theme through a plugin function?
- Where to store the name of a custom table?
- Creating a Link Text like Submit Button in Admin Page
- Beginner advice
- Change the ‘published on’ text?
- WordPress is automatically linking plain text email addresses
- Is Using WordPress Supplied WYSIWYG Advisable?
- How to render a time-of-day string like ’16:42′ with a site’s chosen time format?
- Are block templates incompatible with serialize_blocks?
- WooCommerce get_price returning wrong price when used via ajax
- ServerSideRender and Media Object: attributes passing image data object to php renderer even though it’s not set
- How to filter users list on user_status field with get_users()
- Open Post Thumbnail in New Child Theme File in WordPress
- How to use get_theme_mod in gutenberg editor wordpress?
- Get Current Menu Location inside Nav_Walker
- Customizer: Output default value in Customizer CSS
- Is it possible to change a term slug before being saved to the database?
- How can i upload images in an admin page?
- SQL query for custom taxonomy slugs
- Tried in different ways but sidebar not working?
- Can Page Templates be Applied to Archive and Post Templates?
- Maximum lifetime for nonce
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Clearing caches on plugin uninstall
- How to use a hook to override an update_post_meta call in a plugin?
- Add code inside specific wordpress standard function
- How to customize a permalink (URL) structure?
- Short code not working in boostrap modal dont no why?
- Custom Taxonomy to dropdown box on adminside wordpress
- Create a free scripts and styles template within a plugin
- Is there a way to list all actions registered by a plugin or theme?
- Converting HTML Template to WordPress Theme