0

I am using the following code in my child theme's functions.php file to replace the_author() value (dc:creator node) with the value of an Advanced Custom Fields text field named custom_byline. It seemed to be working like a charm, but there are some posts which inexplicably don't update ... do you see issues with the code I didn't catch?

    if(is_feed()) {  
        $post_id = get_the_ID();
        if (get_field('custom_byline') != '') {
          $creator = get_post_meta($post_id, 'custom_byline', true);
        }
    }  
    return $creator;  
}  
add_filter('the_author','custom_byline_in_feed');
10
  • First of all I would use the same function to check the value and use the value so I would use if(get_post_meta($post_id, 'custom_byline', true)!= ''){$creator = get_post_meta($post_id, 'custom_byline', true);}. After that what do you mean "but there are some posts which inexplicably don't update" ? when updating post you don't get the custom field updated or you don't see what you expect in the feed ? Also please post the full code of your function Jan 20, 2020 at 16:32
  • I'll make the consistency switch you recommend - for cleanliness sake - but it works either / both ways. There are posts in the feed which have custom_byline value but the feed dc:creator is not changed. What I've found since my original post was that some of the custom_byline values contain apostrophes (ex: O'Reilly) and that's causing the issue. Jan 20, 2020 at 16:36
  • try to use str_replace("'","'",get_post_meta($post_id, 'custom_byline', true)); Jan 20, 2020 at 16:43
  • No dice. I was in the midst of trying that when you commented. No change. Jan 20, 2020 at 16:46
  • try to var_dump the custom field and see what's in there Jan 20, 2020 at 16:48

0

Your Answer

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

Browse other questions tagged or ask your own question.