Hot answers tagged

4

to hook in the <head> you would use wp_head. You can read the documentation here. add_action( 'wp_head', 'meta_example' ); function meta_example() { echo '<meta name="description" content="Meta Description for this Page." />'; } // End meta_example() This assumes that your theme has <?php wp_head(); ?> in the <head>.


2

The solution is using added_post_meta and updated_post_meta hook . Here is the working code . add_action( 'added_post_meta', 'add_custom_field_automatically', 10, 4 ); add_action( 'updated_post_meta', 'add_custom_field_automatically', 10, 4 ); function add_custom_field_automatically( $meta_id, $post_id, $meta_key, $meta_value ) { if ( '_my_meta_key' ...


2

update_field() is ACF function so I would guess the issue is with it. From quick look at source it calls get_field_object() and so on, so environment might not be sufficient for it to work correctly during import. There is no "half" state for native meta data, either it exists in database or it doesn't. You could try to stick with native WP API for meta ...


1

WP API has a rest_prepare_post filter (or rest_prepare_CPT if you are working with custom posts) which you can use to modify the JSON response. In your case it will be rest_prepare_joblisting. function filter_joblisting_json( $data, $post, $context ) { $phone = get_post_meta( $post->ID, '_phone', true ); if( $phone ) { $data->data['phone'] = ...


1

$post in the callback function is an array, not an object. So you cannot use $post->id. Change it to $post['id'] and it should work: function slug_get_phone_number($post, $field_name, $request) { return get_post_meta($post['id'], '_phone', true); } I recommend to change _phone to phone_number or something else without underscore prefix. Because _ ...


1

You can hook into the loading of any admin screen with add_action( 'load-post.php', 'tbdn_post_screen' ); function tbdn_post_screen() { // Check here whether you're adding a post or // editing a post by seeing if $_GET['action'] // equals 'edit' then add your meta for post with // ID $_GET['post'] } Details of all of the admin screen ...


1

I found where the problem was. The code was attached to the the_content hook which runs after the thumbnail is generated. Attached the code to post_thumbnail_html and it works now.


1

The meta_value field is longtext, which a quick google reports is 4,294,967,295 characters - I doubt you're exceeding that. Chances are it's an issue with PHP, specifically post_max_size - if this is less than the "huge amount of data" you are referring to, PHP will simply truncate $_POST and you end up with nothing.



Only top voted, non community-wiki answers of a minimum length are eligible