How to use the post_title of custom post type as taxonomy

Is there a hook that actually only fires when a post gets updated and where I can get $post_before and $post_after? You’re probably looking for the post_updated hook. Usage add_action( ‘post_updated’, ‘wpse_264720_post_updated’, 10, 3 ); function wpse_264720_post_updated( $post_ID, $post_after, $post_before ) { //* Bail if this is an autosave if( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE … Read more

Widget for adding HTML markup to a page

If you want to do it the “WordPress-way”, you would create a custom post-type for books called “book” ( For this take a look at https://codex.wordpress.org/Function_Reference/register_post_type ). Then you would create an archive page for that post-type called “archive-book.php”. I hope this helps a little bit. If you need more help, let me know.

Update post terms with custom taxonomy

Yes it is. But you have to know the exact taxonomy’s slug, since colors are not like preserved terms to be generated programmatically. Here is an example of how to do it: // run our function when a post is published add_action(‘save_post’,’update_my_taxonomies’); function update_my_taxonomies($post_id){ // Check if the post has a particular taxonomy if(has_term( ‘blue’, … Read more

Woocommerce: How to change the add to cart text in a certain category? [closed]

You can use the has_term function to check for the desired term. function add_cart_button_replace() { global $product; $link = $product->get_permalink(); $button_text = __(‘+show OFFER’, ‘woocommerce’); // check if the current product has a “product-category” of “free-products” if(has_term(‘free-products’, ‘product_cat’, $product->get_id())) $button_text = __(‘+choose me’, ‘woocommerce’); echo do_shortcode(‘<a href=”‘.$link.'” class=”button addtocartbutton”>’ . $button_text . ‘</a>’); } You … Read more

Correct way to insert taxonomies on page insert

Turns out you can’t use the term slug (for obvious reason of possible duplicate slugs face palm) you need to use the terms ID. $term_id = term_exists( ‘system’, ‘status’ ); $page = array( ‘post_title’ => ‘New Job’, ‘post_name’ => ‘new-job’, ‘post_content’ => ”, ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_type’ => ‘jobs’, ‘tax_input’ => array … Read more