Home › Forums › Quform WordPress › Creating a post and setting category on it
- This topic has 13 replies, 2 voices, and was last updated 4 years ago by Ally.
- AuthorPosts
- December 21, 2019 at 6:32 am #30403akhenatonParticipant
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?January 8, 2020 at 7:38 pm #30447akhenatonParticipantUm, 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.
February 24, 2020 at 9:59 am #30680AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
February 24, 2020 at 10:05 am #30681AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
February 26, 2020 at 9:46 am #30698akhenatonParticipantSincere 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
March 25, 2020 at 2:17 am #30887akhenatonParticipantHey, 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?
March 25, 2020 at 10:37 am #30892AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
March 25, 2020 at 9:50 pm #30894akhenatonParticipantHi, 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.
March 26, 2020 at 11:21 am #30896AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
March 26, 2020 at 7:05 pm #30897akhenatonParticipant” 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”?March 30, 2020 at 10:54 am #30913AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
March 31, 2020 at 3:15 pm #30916akhenatonParticipant“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.
March 31, 2020 at 3:41 pm #30917akhenatonParticipantCorrection: 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.
April 2, 2020 at 10:15 am #30930AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.