0

I am using a REST API with Python to get custom field content from WordPress. When I pull a non custom field like "Title", I can successfully render this with the code:

post_title = post_data_dict.get('title', {}).get('rendered', '')

However, with a custom field, I haven't been able to figure this out. Right now my code looks like this:

video_content = post_data_dict.get('acf', {}).get('content', '')

However this contains the HTML formatting.

Any hints would be greatly appreciated. Thank you.

1
  • This question is similar to: Python code to remove HTML tags from a string. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Jan 27 at 6:53

1 Answer 1

0

I found this post that worked for me: Python code to remove HTML tags from a string

I just used the function:

def cleanhtml(raw_html):
    cleanr = re.compile('<.*?>')
    cleantext = re.sub(cleanr, '', raw_html)
    return cleantext

So, my new code looked like this:

video_content = cleanhtml(post_data_dict.get('acf', {}).get('content', ''))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.