Question

function slb_subscriber_column_data( $column, $post_id ) {  
  // setup our return text
  $output = '';  
  switch( $column ) {    
    case 'title':
      // get the custom name data
      $fname = get_field('slb_first_name', $post_id );
      $lname = get_field('slb_last_name', $post_id );
      $output .= $fname .' '. $lname;
      break;
    case 'email':
      // get the custom email data
      $email = get_field('slb_email', $post_id );
      $output .= $email;
      break;    
  }  
  // echo the output
  echo $output;  
}

function slb_register_custom_admin_titles() {
    add_filter(
        'the_title',
        'slb_custom_admin_titles',
        99,
        2
    );
}

function slb_custom_admin_titles( $title, $post_id ) {
   
    global $post;  
    $output = $title;   
    if( isset($post->post_type) ):
      switch( $post->post_type ) {
        case 'slb_subscriber':
        $fname = get_field('slb_first_name', $post_id );
        $lname = get_field('slb_last_name', $post_id );
        $output = $fname .' '. $lname;
        break;
      }
      endif;   
    return $output;
}

The above is the code from a plugin. I was going through a course on udemy.com. The author is not responsive.

Issue: Although the whole approach was to create a setting without any third party, the author seems to have made the code dependent on the ACF plugin somehow. as soon as I disable the ACF plugin the screen goes blank:

enter image description here

I feel that the culprit is this part: get_field How can I get rid of this. what in general may be used from WordPress functions to extract this information without this?

enter image description here

Was it helpful?

Solution

You can use the default WP function get_post_meta to get meta from the post, here is the link to the official documentation https://developer.wordpress.org/reference/functions/get_post_meta/

For example get_field('slb_first_name', $post_id ) must be replaced with get_post_meta($post_id, 'slb_first_name', true)

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top