Assign category from custom field on post creation and update

After getting year, you may check if category exists using category_exists($cat_name); if not found then create category using wp_create_category( $cat_name, $parent ); after that you may create post using $my_post = array( ‘post_title’ => wp_strip_all_tags( $_POST[‘post_title’] ), ‘post_content’ => $_POST[‘post_content’], ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_category’ => array( 8,39 ) ); // Insert the … Read more

How to check post type when using sanitize_title hook?

As @Jacob mentioned, is an generic utility function used in many contexts and therefore, you might want to either use other approach or hook it selectively through other hook where you would have $post object (e.g. edit_post or other way to define if the post edited is of page type. Something along these lines: <?php … Read more

Calculate price and display on woocommerce product single page under price (simple price, variable price) [closed]

One way to add JavsScript in functions.phhp is to put the JavaScript into a JS file an enqueue it. With wp_enqueue_script(). js/mynicecode.js var x = myFunction(60000, 5.15464, 100); function myFunction(a, b, c) { return Math.round (a * b / c); in functions.php function my_load_scripts($hook) { wp_enqueue_script( ‘mynicecode_js’, plugins_url( ‘js/mynicecode.js’, __FILE__ ), array()); } add_action(‘wp_enqueue_scripts’, ‘my_load_scripts’);