Creating a post and setting category on it

Home Forums Quform WordPress Creating a post and setting category on it

This topic is: not resolved
  • This topic has 13 replies, 2 voices, and was last updated 4 years ago by Ally.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #30403
    akhenaton
    Participant

    In theory that is explained here https://support.themecatcher.net/quform-wordpress-v2/guides/integration/creating-a-post
    but what I want is a little different.
    ?
    add_filter('quform_post_process_1', function (array $result, Quform_Form $form) { $title = $form->getValue('quform_1_3'); $content = $form->getValue('quform_1_4');
    $post = array(
    'post_title' => $title,
    'post_content' => $content,
    'post_type' => 'post',
    'post_status' => 'publish'
    );

    $postId = wp_insert_post($post);
    wp_set_object_terms($postId, 'my_category_slug', 'category');
    return $result
    }, 10, 2);

    Hope the formatting comes out right…
    Your example above assumes I would already know the category for the post,(the “my category slug” line), but I don’t. What I want is to be able to select the category from a list (select, or maybe a list of checkboxes) populated from the categories (post taxonomies) that already exist. How would I do that? Also from what I recall each post type has its own taxonomies, so if I’m looking to create a custom post type, what would the code look like?

    #30447
    akhenaton
    Participant

    Um, notice me senpai? 😀 I realize this was posted during the winter holidays, but we’re now well into the new year… Even a “we’re swamped with work”, but “we ‘ll get to it” would be fine.

    #30680
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #30681
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #30698
    akhenaton
    Participant

    Sincere apologies, I made a mistake with your topic and as a result it was marked as completed, so I didn’t actually see it – I definitely wasn’t ignoring you. Sorry again, I feel terrible about this, to help make it up to you I will extend your support by 6 months on the forums.

    We’re good. Much appreciated.

    Give me some time to experiment. I *have some questions already but I’ll know better what to ask once I do some trials.

    • This reply was modified 4 years, 2 months ago by akhenaton. Reason: used wrong workd
    #30887
    akhenaton
    Participant

    Hey, I’m back. Hope all is well. I am having a bit of a problem with the integration and I’m getting nowhere. I have a rather simple custom plugin made by me based on internet tutorials that defines a custom post type, I can’t seem to get it to work with quform. When submitting the form I get the message “Ajax error” and the submission doesn’t work at all (i.e. the post doesn’t get saved as post nor as a quform entry). I think something within my plugin is interfering with Quform, because the form I created (IOW, Quform itself) works OK if I change code to save it as the regular posts.

    My PHP skills are rather rudimentary, so I can’t figure out what’s wrong and you’d probably make short work of it. I am also confused on how to implement the “Saving data to custom fields (postmeta)” and combine it with “Customizing the post content” from here. https://support.themecatcher.net/quform-wordpress-v2/guides/integration/creating-a-post

    Is it OK if I send you an email with my plugin and my exported form for you to test on your end?

    #30892
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #30894
    akhenaton
    Participant

    Hi, sent you the code. I should be able to make subsequent changes myself, like adding more fields to the post saving routine and displaying them via the template once I see how it’s done, from the maker :j I understood your tutorials individually, but haven’t been able to put them all together. Thank you.

    #30896
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #30897
    akhenaton
    Participant

    ” Actually both the my_quform_load_custom_fields and my_quform_save_custom_fields save the fields on the page with the form, not the actual created post. So if this is not what you want I would remove this code too.”
    It works. The form creates an “entry”. But not an actual post anymore (say, like a draft). I don’t remember how to do that.
    What do you mean they “save the fields on the page with the form, not the actual created post”?

    #30913
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #30916
    akhenaton
    Participant

    “If you wanted the custom field value added to the post that is created you would need to use the post ID returned from wp_insert_post – hope that makes sense.”
    It makes sense, I’ve looked at the wordpress documentation, but I’m no closer to writing my own stuff then I was before. I’ve been trying for a long time to learn programming and I’ve always been let down by the tutorials or books available. And when I say “programming” it is because from what I’ve noticed, all languages seem to share the basics (variables, if clauses, functions, types of data, like strings, integers, etc). I can understand simple examples like “echo Hello world!”, I get the notion of using variables and simple if checks, but once I get to complex, multi-level nested functions I get kind of lost. As you saw, I even managed to create a simple WP plugin, that more or less works, but I’m not sure I’ll be writing a competitor for Quform anytime soon, you know? 😛

    OK, sorry about rambling, to get to the point:
    Yes, I want the form to save those custom fields attached to the post that is created by the form, not to the page the form is on. Creating custom posts from the frontend is the one area where there has been no progress in WordPress since forever. But then again, if there was, form builders would become more or less redundant.

    So if I create a “download” using the Quform form, called, say, “Nvidia Detonator”, it would then create it in the wp_posts table, and also add to the wp_postmeta table the custom fields like “price”, “size in MB”, “download link 1”, and any other custom field I may decide to add to the form.

    Also, I haven’t been able to find in the documentation how to include the custom fields in the WordPress theme. Maybe I missed it. True, there are tutorials on the web on how to do that, but usually they only explain how to display simple strings, but not complex data types like selects, checkboxes and the like, which you can create using Quform.

    #30917
    akhenaton
    Participant

    Correction: I think I found the “how to get the data”, https://support.themecatcher.net/quform-wordpress-v2/guides/basic/getting-form-values-data-types, but that still leaves the “displaying and formatting it” part. Once I get to more complex elements like arrays, I need someone to show me how it’s done first. After that I can usually apply the example to other elements.

    #30930
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy