• Hello, I’m developing a plugin to convert a web in a photo contest website and I’m facing a problem I can’t figure out the solution. What I do:
    1. I have a front end form for the user to submit a CPT with a title and image. The CPT remains as a draft until someone takes a look on it.
    2. On an options page I use a function to publish the posts and assign to them a custom taxonomy:

    $idpost = get_the_id();
    $my_post = array(
        'ID'			=> $idpost,
        'post_status'	=> 'publish'
    );
    wp_set_object_terms($idpost, 'votacion', 'temas_liga', false);
    wp_update_post( $my_post );

    3. I then have a single taxonomy template to show them. In that single page I have a form for the scoring of the image.
    Everything works almost perfect: the images go to draft, then go to published and got the term, and I can see it on the single tax page.
    But the field with the score is not showing. I can see the submit button, the form is created, even the div for the field, but it is empty when you see the html.
    More funny is that if I go in the backend to edit the CPT and I just save the CPT without making any change, then I go to the frontend single page and then the scoring field appears.
    I have an image to explain better, the image on the left has been saved on the backend and the image on the right has not been saved on the backend: Image

    Thanks for your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    FYI, I’m blocked from seeing your image. No matter, I think I understand what’s happening. Have you tried checking the frontend page sometime later without going to the backend? It maybe that the server has not finished updating the DB when the next request comes through, thus it still appears as empty.

    Another possibility is saving the score does not update the cache, but editing the post does. If the frontend page is loaded from cache, the score will never appear until the cache is flushed or updated.

    Thread Starter alexgagi

    (@alexgagi)

    Dear @bcworkz, thanks for your response and sorry about the image link.
    Now I hope you can see it: Image correct.
    About your response, I have not explained well, and without image it is difficult to make me understand.
    It’s not a question of time, because even days after the field is still not in there. But the problem is not that the scoring does not save, is that the field (the space) to score doesn’t even appear.
    I think the problem is with wp_update_post(), something is missing when I publish the post using this function. It makes me mad…
    Thanks a lot.

    Moderator bcworkz

    (@bcworkz)

    Thank you for making the image accessible, it does explain a lot!

    I see you are using ACF, which I am not very familiar with. My understanding is you can define fields and forms, then cause them to display by using a shortcode. If that is incorrect, my apologies. Based on my marginal understanding, it appears the shortcode is not being expanded by ACF code for some reason. There is something about how the form is output that bypasses the part of WP that expands shortcodes.

    Then when it is saved in the backend, that part works. I don’t know enough about your site to speculate how this can be happening, but I can tell you that you can force shortcode expansion when it is not happening automatically by passing the content through do_shortcode(). When you output the returned content all shortcodes within will be expanded, provided they were properly registered beforehand.

    Which points to the other possibility: that for some reason ACF cannot register its shortcode before the form is processed. Why this would happen I could not say, only that it is a possible explanation.

    I know I have not answered your question, but hopefully this gives you a better idea where to search for the actual cause or how to work around it. Good luck!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem publishing a post using wp_update_post()’ is closed to new replies.