0
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

1 Answer 1

2

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)

3
  • Thanks before posting I tried that(='get_post_meta) looks like there is something more to this underneath than what appears at the periphery.
    – WordCent
    Commented Apr 18, 2021 at 15:43
  • $post_id can be called directly or we need to store that in a certain variable?
    – WordCent
    Commented Apr 19, 2021 at 5:31
  • Appreciate your help, finally, it worked.
    – WordCent
    Commented Apr 19, 2021 at 5:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.