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

With what hook can I address all posts from all custom post types when they are published?

What about using save_post or wp_insert_post hook, both have @param     int               $post_ID     Post ID. @param     WP_Post     $post          Post object. @param     bool            $update     Whether this is an existing post being updated or not. as parameters. It is pretty self-explaining that the $update can be used to determine, if it … Read more

In a plugin, why is add_action(‘init’) not executed before the plugin is activated?

WordPress is an application and everything that is run within that application is called by hooks. Then 2 main hook functions are add_action and add_filter, but as you saw, register_activation_hook and register_deactivation_hook are other functions that are used in the context of activation and deactivation. There exist more hook defining functions, like functions that will … Read more

Can i check if user is doing any ajax request?

You’d be better off moving your function that updates the meta to a hook that runs on the front end and during AJAX calls. Then you don’t need to bother about checking if the request is an AJAX request or not. init is a good choice for this: function wpse_297026_update_user_activity() { update_user_meta( get_current_user_id(), ‘last_activity’, time() … Read more

Action ‘save_post’ not working for quick edit

It’s just a guess, since I haven’t tested your code, but… There is a part that looks pretty sketchy for me: All your actions are run only if this condition is true: if(isset($post_type) && $post_type == “listings”){ And where that $post_type variable comes from? $post_type = get_post_type(); So you don’t pass any post_id to that … Read more