PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Post to category being viewed dynamically...

  1. Setting up a WP site that has a similar structure to craigslist.. There are many regions and each region is a category. I've put a form for submitting a listing in my category.php file. I need the form to post to the category that is being viewed. How would I achieve this?

    What I have tried so far... :
    Viewing and using the source code. I found that there was a piece of code that looked liked this:
    action='/?cat=3#gf_1'>
    .. And I thought, oh that's where it tells it to post to the specific category... So I change it to:
    action='/?cat=<?php the_category_ID(); ?>#gf_1'>

    Which seemed to work but it would still post to category 3. I think that line just showed what category page you were in by default.

    I've searched through the documentation and forum, and of course have considered adding a hidden category field that is pre-populated, but not sure if that would work. As I understand it, you have to place the following in your functions.php file.. :

    add_filter('gform_field_value_your_parameter', 'my_custom_population_function')
    function my_custom_population_function($value){
        return 'boom!';
    }

    The return value would have to be something like the_category_id but I'm not sure how to merge those two things together. And even if I could, I'm not sure that it would work. And also it appears that you *have* to set a category for the form to post to in the post title. So how would I stop it from posting to more than one category and only posting to the category which the user is currently viewing?

    Thanks in advance.

    Posted 12 years ago on Monday November 14, 2011 | Permalink
  2. Hi Sallana,

    I'd recommend the hidden field approach which you would dynamically populate with the current category ID. Using the gform_after_submission hook you could retrieve the value populated in the hidden field (category ID) and then use the wp_set_object_terms function.

    Here is a related thread that might have some more information for you:

    http://www.gravityhelp.com/forums/topic/add-parent-post-category-with-hookfilter

    Posted 12 years ago on Tuesday November 29, 2011 | Permalink

This topic has been resolved and has been closed to new replies.