Insert custom postmeta when custom post type published

Newer New solution: function wpse153622_transition_solution( $new_status, $old_status, $post ) { if ( $new_status != $old_status && ‘publish’ === $new_status && ‘my-solution’ === $post->post_type ) { update_post_meta( $post_id, ‘my_json’, ‘json’ ); } } add_action( ‘transition_post_status’, ‘wpse153622_transition_solution’, 10, 3 ); This should trigger only when 1. the new post status isn’t the same as the old one … Read more

How to access author data from header action

The global $authordata variable is only available by default when $wp_query->is_author() && isset($wp_query->post) condition is satisfied. It means that you can’t access $authordata inside a single post page. You may try to get author data via $wp_query: add_action(‘wp_head’, function() { global $wp_query; $userdata = get_userdata($wp_query->post->post_author); $avatar_url = get_avatar_ur($userdata->user_email); … }, 10, 0);

add_action and do_action

Please check also wp-includes/general-templates.php but wp_head() hooks ‘wp_head’ like this: function wp_head() { do_action( ‘wp_head’ ); } So I would change your code like this for example: add_action( ‘wp_head’, ‘my_prepare_pick_data’ ); add_action( ‘my_add_meta_tags’, ‘my_add_meta_tags’ ); function my_prepare_pick_data() { $pick_data = new YourPickDataClass(); // change this as you like do_action( ‘my_add_meta_tags’, $pick_data ); } function my_add_meta_tags( … Read more

Why does my wp_safe_redirect output the ERR_TOO_MANY_REDIRECTS error?

Because you’re in an infinite loop. When the user visits the site, init fires, and they get redirected to themes.php?page=theme_setup Then they arrive on themes.php?page=theme_setup and the init hook fires and redirects them to themes.php?page=theme_setup So then they arrive on themes.php?page=theme_setup and the init hook fires and redirects them to themes.php?page=theme_setup So then they arrive … Read more

Payment before publishing post

Use below code add_action(‘transition_post_status’, ‘send_new_post’, 10, 3); // Listen for publishing of a new post function send_new_post($new_status, $old_status, $post) { if(‘publish’ === $new_status && ‘publish’ !== $old_status && $post->post_type === ‘post’) { // Do something! } }

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