Dynamically Create Terms in Taxonomy when Custom Post Type is Published. Almost There!

You’re almost there – the problem is you’re trying to access the $post object when the function only receives the post ID. add_action( ‘publish_country’, ‘add_country_term’ ); function add_country_term( $post_ID ) { $post = get_post( $post_ID ); // get post object wp_insert_term( $post->post_title, ‘country_taxo’ ); }

How to modify wp_ajax function?

You can jump in front of an AJAX hook by specifying a higher priority (i.e. lower number), like this: add_action( ‘wp_ajax_find_posts’, ‘wp_ajax_find_posts’, 0 ); NB: works because 0 < 1

WP Login forms action URLs displayed as pretty URLs in browser (ex with Restore Password)

Step 2. However, when I submit an un-matching password, the form is redisplayed and URL is now http://example.com/wp-login.php?action=resetpass&key=xyz&login=zyx. Notice, that action has changed. When I attempt this with an invalid key I get redirected to http://example.com/wp-login.php?action=lostpassword&error=invalidkey. Anyway, the infinite loop is occurring because you are the condition in_array( $action, array(‘rp’, ‘resetpass’) ) remains true for … Read more

Using hooks to place content in theme dynamically

If you’re the parent theme Developer, you can add the hook in your parent themes file and then use it in a custom function in your child theme. 1. Add Hook To Parent Themes File <?php do_action( ‘after_wp_footer’ ); ?> 2. Create Function For New Hook in Parent Theme function create_after_footer_hook() { do_action(‘after_wp_footer’); } 3. … Read more

wp_logout action not working

pls try below code function remove_user_cookie() { setcookie(“woak”); setcookie(“woai”); } add_action(‘wp_logout’, ‘remove_user_cookie’); apart why you use cookie to storing some value ? suggest you to use session

Make the ‘all’ filter default instead of ‘mine’ in a custom post type

answer ^^ add_action( ‘load-edit.php’, function() { global $typenow; // Not our post type, bail out if( ‘community’ !== $typenow ) return; // Administrator users don’t need this, bail out if( current_user_can(‘add_users’) ) return; // Only the Mine tab fills this conditions, redirect if( !isset( $_GET[‘post_status’] ) && !isset( $_GET[‘all_posts’] ) ) { wp_redirect( admin_url(‘edit.php?post_type=community&all_posts=1’) ); … Read more

add_meta_boxes action with refresh on save

So I managed to cobble something together with a bit of javascript… It’s hacky but somewhat elegant I think. add_action(‘admin_init’, function () { if ( current_user_can(“send_notifications”) ) { $post_types = [“post”, “go_live”]; foreach ($post_types as $post_type) { add_meta_box( ‘cabtv_notif_on_post’, ‘Notifications’, function ($post) { wp_nonce_field( ‘cabtv_notif_metabox’, ‘cabtv_notif_metabox’ ); $sent = (bool) get_post_meta( $post->ID, ‘cabtv_notifications_sent’, true ); … Read more