Sign Up

Captcha Click on image to update the captcha.

Have an account? Sign In Now

Sign In

Discover the power of expert communities in searching for solutions.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question. Please subscribe to paid membership

Forgot Password?

Don't have account, Sign Up Here
Please subscribe to paid membership

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

GetSolu.com

GetSolu.com Logo GetSolu.com Logo

GetSolu.com Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Home
  • About Us
  • Blog
  • Contact Us
Home/ Problems/Q 4031
Next
Need More Solution

GetSolu.com Latest Problems

Anonymous
  • 0
Anonymous
Asked: April 5, 20232023-04-05T07:21:35+00:00 2023-04-05T07:21:35+00:00In: Website Development

How to update WordPress post content with wpapi for nodejs without losing shortcodes?

  • 0

I am working on a project that involves using wpapi for nodejs to interact with WordPress posts. I want to update an existing post by adding some new content to its original content. However, I am facing a problem with the content field of the wpapi response. When I use wp.posts() to get the content of a post, I only see the rendered result, which does not include any shortcodes that are present in the WordPress editor. If I simply append some data to this content and use PUT to update the post, I will lose the shortcodes and mess up the formatting of the post. How can I solve this problem? Is there a way to get the raw content of a post as it is in WordPress, or to append content without affecting the shortcodes? I appreciate any help or guidance on this issue. Thank you.

wordpress
  • 1 1 Solution
  • 23 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Solution

    • Voted
    • Oldest
    • Recent
    1. Mr. Zero
      Mr. Zero
      2023-04-05T07:25:08+00:00Added an answer on April 5, 2023 at 7:25 am

      One possible solution to your problem is to use the `content.rendered` and `content.raw` fields of the wpapi response. The `content.rendered` field contains the HTML output of the post content, which includes the shortcodes. The `content.raw` field contains the raw text of the post content, which does not include the shortcodes. You can use these fields to manipulate the content of a post without losing the shortcodes.

      For example, suppose you want to add some new content to the end of an existing post. You can use the following steps:

      1. Use `wp.posts().id(postId).get()` to get the post object with the `content.rendered` and `content.raw` fields.
      2. Use a regular expression or a HTML parser to extract the shortcodes from the `content.rendered` field and store them in an array.
      3. Use a string concatenation or a template literal to append your new content to the `content.raw` field.
      4. Use a loop or a map function to insert the shortcodes back into the `content.raw` field at their original positions.
      5. Use `wp.posts().id(postId).update({content: content.raw})` to update the post with the modified content.

      This way, you can update an existing post by adding some new content to its original content without affecting the shortcodes or the formatting of the post. I hope this helps you with your project.

      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    Add Your Problem

    Stats

    • Problems 38
    • Solutions 45
    • Best Solutions 7
    • Users 51
    • Popular
    • Solutions
    • Anonymous

      Create and print invoice from website used Woocommerce with WordPress

      • 2 Solutions
    • Anonymous

      Need show post by timeline on my blog website

      • 2 Solutions
    • Anonymous

      I want to find a software collage of photos with ...

      • 2 Solutions
    • Anonymous

      How to hide products that ware sold out in woocommerce?

      • 2 Solutions
    • Anonymous

      SMTP Error: Could not authenticate. Zoho mail

      • 2 Solutions
    • Mr. Zero
      Mr. Zero added an answer According to the Avada licensing terms and conditions, a regular… September 21, 2023 at 8:39 am
    • Mr. Zero
      Mr. Zero added an answer Hi, Does .link domain affect SEO? Yes, it can. Google… September 18, 2023 at 2:36 pm
    • Mr. Zero
      Mr. Zero added an answer The Avada demo library and plugin are stored on the… September 8, 2023 at 2:11 pm
    • Kevin Hernandez
      Kevin Hernandez added an answer Recently, many people also feel that selling on e-commerce platforms… July 28, 2023 at 1:57 pm
    • Mr. Zero
      Mr. Zero added an answer Hello, thank you for trusting and sending us your problem.… July 27, 2023 at 2:07 pm

    Top Members

    Pemberton Lockwood

    Pemberton Lockwood

    • 0 Problems
    • 4 Solutions
    Master
    Kevin Hernandez

    Kevin Hernandez

    • 0 Problems
    • 3 Solutions
    Master
    Idris Rhiannon

    Idris Rhiannon

    • 0 Problems
    • 3 Solutions
    Master

    Trending Tags

    affiliate marketing (1) ai (1) avada (3) career development (1) freelance job (1) income generation (1) online business (2) paywall (1) woocommerce (6) wordpress (15)

    Explore

    • Home
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges

    Footer

    At GetSolu, we hold the belief that discovering solutions to the challenges that you may face should not be an isolated pursuit. This is why we have established a community comprised of proficient experts and knowledgeable individuals who possess a strong desire to assist you in surmounting your difficulties. All that is required of you is to provide a comprehensive description of the issue that you are experiencing, and our team of experts will furnish you with customized solutions that are tailored to your needs. Our unwavering dedication to aiding you in locating the appropriate solutions and connecting you with the necessary resources to thrive remains resolute. There is no need to hesitate. Join our community today and witness the potency of collaborative problem-solving.

    • Terms of Service
    • Privacy Policy

    Members

    • Gifts
    • Badges

    Follow

    © 2023 Get Solu. All Rights Reserved
    With Love by Mr. Zero.