Support

Account

Home Forums Backend Issues (wp-admin) How to get field when editing post?

Solved

How to get field when editing post?

  • Here is my situation:
    I want to let some users have some capability temporary when they choose some option.
    So,I use this code:

    
    function author_cap_filter( $allcaps, $cap, $args ) {
    	global $current_user;
    	
    	if( the_field('is_tw')=="true" )  //"is_tw" is the custome field I set in ACF.
    	{	
    		global $post;
    		$id = $post->ID;
    		$status = get_post_status($id);
    		
    		$allcaps['publish_posts'] = 0; //This is the limitation of diable the ability of publishing post temporary.
    	}
    
    	return $allcaps;
    
    }
    add_filter( 'user_has_cap', 'author_cap_filter', 10, 3 );
    

    However,it’s useless.Can somebody tell me how to fix this?

  • I found the solution,just use the get_field().
    <?php $field = get_field($field_name, $post_id, $format_value); ?>

    http://www.advancedcustomfields.com/resources/functions/get_field/

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to get field when editing post?’ is closed to new replies.