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.
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?
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;
}
Super, i’ll give that a go, thank you! So you would title the pages “100” and “200” in that example?
Sorry, silly question – figured out what you meant by page ID and your suggestion works. Thank you for your help!
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! 🙂
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.
🙂 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!
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
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.
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 :).