Try instead
update_post_meta($post->ID,'_yoast_wpseo_primary_category',$childid);
Use below function:
function wpseoPrimaryTerm($taxonomy, $postID, $term){
if ( class_exists('WPSEO_Primary_Term') ) {
// Set primary term.
$primaryTermObject = new WPSEO_Primary_Term($taxonomy, $postID);
$primaryTermObject->set_primary_term($term);
// Save primary term.
$primaryTermObjectAdmin = new WPSEO_Primary_Term_Admin();
$primaryTermObjectAdmin->save_primary_terms($postID);
}else{
echo 'Class WPSEO does not exit';
}
}
Where $taxonomy - taxonomy name, $PostID - $post->ID, $term - $childid
Related Posts:
- Auto-Select Parent Category as Primary
- what is correct way to hook when update post
- How to update custom fields using the wp_insert_post() function?
- PHP/Manual use of images? – 2 Questions
- Custom Yoast Breadcrumbs URL
- Why is my custom meta box input not saving
- Action ‘save_post’ not working for quick edit
- Save selected item from dropdown menu in a meta box as a metadata value for a custom post type
- How can i create a function to get youtube video time
- Second select list values are not saved after clicking update
- Update Custom Field on Imported Post Creation
- Executing `createimagefrompng()` from save_post hook (or equivalent hook)
- Can I change the contents of a description meta tag generated by Yoast?
- wp_insert_post not working
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- Can’t get wp_insert_post to work
- save imported posts as drafts
- Getting error when trying to implement site-wide breadcrumbs in Twentytwentyone Theme [closed]
- Don’t insert if permalink is the same?
- Can’t find infinite loop cause
- Use of wp_insert_post and parameters
- Getting error when using wp_insert_post()
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Display Yoast meta-description `wpseo_desc` within loop of categories and fail silently if no data is set [closed]
- Custom meta box values are not getting saved for my custom post type
- wp_insert_post() with HTML tags using PHP
- WordPress yoast seo plugin – parse snippet var in meta description
- Add new post in existing categories using wp_insert_post
- get post id from wp_insert_post for get_template_part
- Returning all values from foreach in function php [closed]
- Generate CSV file and add data as a new wordpress custom post
- update_post_meta() not saving data inside of save-post filter
- Genesis / custom template page / setting the page title and meta desc
- Class property seems to lose scope, attached to save_post action?
- How to use `wp_insert_post()` and `get_permalink()` functions?
- save_post action inside a custom metabox class not working
- how to add datas in taxonomy to post with wp_insert_post
- Workaround for og:image unsupported webp image type, Yoast SEO?
- WordPress: Export/Import Yoast meta title & description to custom taxonomy
- How to check post meta isset or not empty during publish/save post?
- save_post trigerred twice
- Custom function that re-writes page title breaks when the Yoast plugin is activated
- How can I pass php code as a content while publishing a post
- Meta inserted through wp_insert_post gets messed up
- Using $this with an anonymous function in filters
- How to display custom seo title before the loop?
- how to call other plugins once custom post has been inserted
- Adding user meta to post meta wp_insert_post() not working
- Front end post submissions do not get submitted in the category
- Save data of select list after clicking save
- Post content not showing some content
- How to extend the page editor?
- upload images on front by user using form
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- seo meta description issue in google search
- PHP – Multiple variables in insert post array
- Can’t send form data to wpdb when URL has query string
- Save_Post change Custom Post Type Post title to post id number
- Can’t insert into a database wordpress
- Using register_activation_hook in classes
- How to create a custom config file and get data using inline JS in a wordpress page
- Image upload via FTP to wordpress media library
- WP database error for comments_popup_link()
- if file_exists not working with wp_enqueue_style
- Unable to set right time in admin and frontend template
- Check if current page is wp-admin
- WordPress custom image size on custom field image
- WordPress WP_Query() Not working properly
- My Own layout in WooCommerce pages [closed]
- Random order of WP_Query results with highest meta value
- How to style options page in dashboard?
- multiple taxonomy select display only one in front end
- Error using WordPress $wpdb object to get result from custom table
- In WordPress, how do I get the number of posts next to single_cat_title(”); in the category.php file?
- Need help with Code Correction php+wordpress
- form $_post action value gets truncated after it passes through two forms
- duplicate entries in database while using save_post or wp_insert_post
- How to echo the_title from an array of posts?
- WordPress -> If Is Role Subscriber Show Image?
- Using color schemes with Color Picker
- What should I write in the post action of this front end post form?
- Payment field disappears on custom Paypal plugin
- Creating a brand attribute as a variable
- Illegal string offset in PHP function in via Theme Customizer
- Loop for recently (updated_post_meta) posts?
- How to retrieve quantity input field by id in woocommerce
- My single.php page skips the first div tag
- Handling form actions in WordPress
- Shortcode’s output to use as other shortcode’s parameter
- PHP code printed into CSS classes
- How to hook into the subscriber /wp-admin/index.php page?
- What syntax is this? “{{post.price}}”
- How to handle the structure of page/taxonomy/post without making wordpress get confused with the url
- Add two or multiple functions in WordPress Post or Page
- Can’t put a hyperlink on Featured Post’s Image
- special characters not supporting in wordpress
- WP Simple Fields – Single repeatable field inside repeatable field group
- Upgrade wordpress core programmatically with PHP [closed]
- Too many if’s and else if’s ?? – Must be better way [closed]
- SQL – How to echo out inside of where statement