got stuck on this as I need to do a string replace for only one page, which is being output as an old format XML atom feed, so I cannot use the inbuilt WP Atom feed that we thought would work.
So, we have a custom post box in our WP/CMS to output a news story without certain markup, to remain a clean item. However, for the XML out put (basically using custom RSS/Atom template for custom page), trying to do stuff like this and not getting it right
Upshot need to output the post field inside custom RSS feed by calling the ACF field, in this case ‘cleanpostbox’ … but when ‘printed’ in the template page, replace the paragraph open/close tags. Will also need to do same for anchor links, but cannot even get this to work right.
$text = get_field('cleanpostbox');
$stripped_text = str_replace(array('<p>','</p>'),('<apxh:p>','</apxh:p>'),$text);
Tried a bunch of things including custom function targeting the single post page 55813, etc. Tried doing array replacement on the_content and just not getting there. Thought I’d try this forum for the rare ‘hwlp’ before I go hire sonmbody who could likely sort it in three shakes of a lamb’s tail.
Not a newbie to WP (since 2005), but I don’t code PHP daily. Hence the duh here. TIA!
thanks for reply.
Basically, I need to replace all the paragraph tags with
apxh:p (opening and closing tags)
and also replace all the anchor link tags
with similar custom XHTML ATOM coding.
So need to do string replace of a 400 word text block for news items, which is in a ACF custom field which we insert same time as doing a ‘dirty’ version of the news in the normal content field (we don’t use Gutenberg).
Trying to output a custom RSS/atom feed, and in the template call the field, but do string replace on the output as we can’t have [CDATA for the feed, and needs the custom coding on the paragraph and anchor links.
Hope that made sense.
I think it’ll help you
Use str_replace() with fewer elements in replace than find:
I am just giving an example to you with word of hello world
$find = array(“Hello”,”world”);
$replace = array(“B”);
$arr = array(“Hello”,”world”,”!”);
Thanks folks. Will be getting back to this Sat. morning as had some wonky client project while this issue is for my own stuff.
Wrinkle I ran into is that the ACF field I’m using actually puts double
So would need to replace with
And also replace
'<a href>' with
I think I’m going to have to hire an ACF pro on this one!
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.