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;  
  • 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 – Andrea Somovigo Jan 20 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. – whakawaehere Jan 20 at 16:36
  • try to use str_replace("'","'",get_post_meta($post_id, 'custom_byline', true)); – Andrea Somovigo Jan 20 at 16:43
  • No dice. I was in the midst of trying that when you commented. No change. – whakawaehere Jan 20 at 16:46
  • try to var_dump the custom field and see what's in there – Andrea Somovigo Jan 20 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.