• Resolved domcoutts

    (@domcoutts)


    I have two types of categories, for which I would like to have separate add.php forms for each.. One page will allow users to create an advert for one type of category, and a second page will only allow users to create adverts for the other category.

    I have a membership association with two membership levels, each able to post an advert to a different category. I can hide the pages using shortcode, but need to effectively predetermine the advert category for each page.

    Any help gratefully received.

    https://ww.wp.xz.cn/plugins/wpadverts/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    You actually need two different form schemes not different add.php template files, the form scheme you can manipulate using adverts_form_load filter http://wpadverts.com/documentation/custom-fields/, but i am afraid it will not allow you to set predefined category, it will just allow to add, edit and remove fields from the form.

    Thread Starter domcoutts

    (@domcoutts)

    Thanks for your quick reply.
    I guess I can hide a category on the form scheme, which would only allow people to select the categories left available to them, that would work.
    How do I choose which form scheme is loaded?

    Plugin Author Greg Winiarski

    (@gwin)

    I imagine you could have the [adverts_add] on two pages one with ID = 100 and the other with ID = 200. When loading the form you can check on which page you currently are and based on this remove the category field

    add_filter( "adverts_form_load", "customize_adverts_add" );
    
    function customize_adverts_add( $form ) {
      if( $form['name'] != "advert" ) {
        return $form;
      }
    
      foreach( $form["field"] as $key => $field ) {
        if( is_page( 200 ) && $field["name"] == "advert_category" ) {
            unset( $form["field"][$key] );
        }
      }
    
      return $form;
    }
    Thread Starter domcoutts

    (@domcoutts)

    Super, i’ll give that a go, thank you! So you would title the pages “100” and “200” in that example?

    Thread Starter domcoutts

    (@domcoutts)

    Sorry, silly question – figured out what you meant by page ID and your suggestion works. Thank you for your help!

    Thread Starter domcoutts

    (@domcoutts)

    Just trying to adapt your code slightly so that instead of removing the category field entirely, it hides a category with a specific ID. Is this possible as I’m struggling!? Thank you in advance… i promise to make a donation! 🙂

    Plugin Author Greg Winiarski

    (@gwin)

    Try

    add_filter( "adverts_form_load", "customize_adverts_add" );
    
    function customize_adverts_add( $form ) {
      if( $form['name'] != "advert" ) {
        return $form;
      }
    
      foreach( $form["field"] as $key => $field ) {
        if( is_page( 200 ) && $field["name"] == "advert_category" ) {
            $form["field"][$key]["options_callback"] = "my_adverts_taxonomies";
        }
      }
    
      return $form;
    }
    
    function my_adverts_taxonomies() {
    
        $args = array(
            'taxonomy'     => 'advert_category',
            'hierarchical' => true,
            'orderby'       => 'name',
            'order'         => 'ASC',
            'hide_empty'   => false,
            'depth'         => 0,
            'selected' => 0,
            'show_count' => 0,
            'exclude' => array( 1000 )
        );
    
        include_once ADVERTS_PATH . '/includes/class-walker-category-options.php';
    
        $walker = new Adverts_Walker_Category_Options;
        $params = array(
            get_terms( 'advert_category', $args ),
            0,
            $args
        );
    
        return call_user_func_array(array( &$walker, 'walk' ), $params );
    }

    But replace 1000 with actual Category ID you wish to hide.

    Thread Starter domcoutts

    (@domcoutts)

    🙂 You’re amazing! Thank you – I would have had no idea how to accomplish that!
    Great app, great support and will very happily send you a donation for all your work. Thank you!

    Plugin Author Greg Winiarski

    (@gwin)

    Sure, no problem :), there is no need for donation, but i would be thankful if you could write a short one or two sentence review here https://ww.wp.xz.cn/support/view/plugin-reviews/wpadverts

    Thread Starter domcoutts

    (@domcoutts)

    All done 🙂 thank you again. Was going to send a donation anyway but can’t find a way of doing so. You have my full gratitude for all your help.

    Plugin Author Greg Winiarski

    (@gwin)

    Thanks! I actually do not have donation link anywhere, but if you would like to make some kind of donation, you can get one of premium add-ons instead http://wpadverts.com/extensions/, that would be a win-win situation :).

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Separate add.php forms for different categories’ is closed to new replies.