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
- Remove datePublished and dateModified from Yoast Schema output on WordPress website
- How to add query string at the end of sitemap Yoast SEO
- Why does my custom slug only show in Gutenberg editor after page refresh?
- Outputting a custom field in PHP
- need help to arabic text in wordpress
- Where to place PHP for shortcodes
- Magento and WordPress URL integration [closed]
- Sorting Meta Fields?
- Hide a div from a particular page and single pages in WordPress
- How to export database correctly for local to online
- Search box background on a different page template
- !in_array doesnt recognize category
- Cron job to call php to email last 24 hours posts
- I am trying to call external database recieving error
- WP Ecommerce: Display the “Order Notes” as column in the Sales Log [closed]
- How can I order metaboxes in my posts in WordPress?
- Custom fields randomly stop working
- the_post_thumbnail unless video id is added
- get_category only returning details for ‘uncategorized’
- Creating a function that sanitizes the custom metabox excerpt
- WordPress Website Featured Image Replacement Issue
- Can’t upload files
- Custom field within shortcode
- Post Title Not showing up
- syntax error unexpected ‘}’ at 364 line
- get_post_meta no longer working
- Advanced Taxonomy query, with 3 post types
- Difference in Get Variable Location
- Highlight posts currently being edited on multiple editor site?
- Keeps asking Connection Information upon update to 3.5.1 (but not for plugins?)
- MySQL database migration to WordPress
- Display selected parts from selected pages on the frontpage?
- How to check “From Email” via WordPress before an email is sent
- Why I can download any file except PHP files from a URL but I can download any from another site?
- How do I unserialize this?
- Target all images that are not the first attachment
- How to style this wp_list_pages markup
- dynamically filter by category via sub-menu
- how to remove sidebar from particular one page
- How to callback custom field text
- WP Query conflict on tag.php and category.php template