Execution of JavaScript on save post

Do it like shown below, as suggested by @gyo and done by @Howdy_McGee in his answer. function admin_queue( $hook ) { global $post; if ( $hook == ‘post-new.php’ || $hook == ‘post.php’ ) { if ( ‘targeted-posttype’ === $post->post_type ) { wp_enqueue_script( ‘custom-title-here’, bloginfo( ‘template_directory’ ) . ‘/scripts/custom-script.js’, ‘jquery’, ”, true ); } } } … Read more

Return code from save_post action?

Actions should not return anything, and action hooks are not built to do anything with a returned value. (That is what filters are for.) If you look at the source for that particular hook, you can see that even if you return something nothing happens. Whatever you return isn’t captured. It vanishes from the code. … Read more

Set Primary category using the Yoast SEO plugin

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

wp_insert_posts Fatal error: Maximum function nesting level of ‘100’ reached, aborting!

Fixed the problem I’ve added this line before the insertion of the posts. remove_action(‘save_post’, __FUNCTION__); final code: add_action(‘save_post’, ‘save_post_func’); function save_post_func(){ remove_action(‘save_post’, __FUNCTION__); include_once(ABSPATH . WPINC . ‘/feed.php’); $rss = fetch_feed($url); if (!is_wp_error($rss)) { $maxitems = $rss->get_item_quantity(5); $rss_items = $rss->get_items(0, $maxitems); foreach ($rss_items as $item) { wp_insert_post(array(‘post_title’ => ‘a’)); } } }

Update Custom Field on Imported Post Creation

There is a hook that worked for me in most case while those 3 hooks you use fail. It’s transition_post_status : add_action(‘transition_post_status’, ‘sterilize_vehicle_information’, 10, 3); function sterilize_vehicle_information( $post, $new_status, $old_status) { $internet_price = get_field(‘internet_price’,$post->ID); if( $new_status == ‘publish’ && old_status != ‘publish’ ) { update_post_meta( $post->ID, ‘internet_price’, preg_replace( “/[^0-9]/”, “”, $internet_price ) ); } } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)