• Resolved snieroda86

    (@snieroda86)


    Hi,
    I use Custom Field add-on . I made two different forms with different fields: [adverts_add form_scheme=”cats”] , [adverts_add form_scheme=”dogs”] . Now I want to dispaly [adverts_list] from “dogs” on page X , and [adverts_list] from “cats” on page Y .
    And second thing – i would like to add HIDDEN field with assigned categories to both forms – possible?
    Thanks for Your help!
    Sebastian

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

    (@gwin)

    Hi,
    you can add the code below in your theme functions.php file

    
    add_filter( "shortcode_atts_adverts_list", "filter_by_form_scheme_args", 10, 3 );
    function filter_by_form_scheme_args(  $out, $pairs, $atts  ) {
        if( isset( $atts["add_form_scheme"] ) ) {
            $out["add_form_scheme"] = $atts["add_form_scheme"];
        } 
        return $out;
    }
    add_filter( "adverts_list_query", "filter_by_form_scheme", 10, 2 );
    function filter_by_form_scheme( $args, $params ) {
        if( ! function_exists( "wpadverts_custom_fields_get_form_scheme" ) ) {
            return $args;
        }
        if( isset( $params["add_form_scheme"] ) ) {
            if( ! is_array( $args["meta_query"] ) ) {
                $args["meta_query"] = array();
            }
            $scheme = wpadverts_custom_fields_get_form_scheme( "add", $params["add_form_scheme"] );
            $args["meta_query"][] = array( 
                "key" => "_wpacf_form_scheme_id", 
                "value" => $scheme->ID 
            );
        }
        return $args;
    }
    

    Once you do that you can use the [adverts_add] as [adverts_add add_form_scheme="cars"] to filter the Ads by scheme.

    I am not sure about your second question?

    Thread Starter snieroda86

    (@snieroda86)

    Hi Greg ,
    I can’t use it ?? . After adding your code and shortcode [adverts_add add_form_scheme=”cars”] , it displays the form for adding adverts (I suppose your solution is ok, only I did not understand something). But I want to display adverts from three different forms on three different sites . I know I can display posts from specific categories , but I do not want to allow the user to choose a category . Therefore, I would like to assign a specific category to a specific form, and this category would be hidden . After that I could display ads from a specific category . Here is my site https://www.mygame.com.pl

    **********************
    Second question: by using Custom fields add-on i made dropdown list in my form with five “sport discipline” . Now i want to filter my posts by “sport discipline” . What i need to do?
    I would be very grateful for your help

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    i made a mistake in the shortcode usage, the code above it should be ok, the shortcode to use is

    
    [adverts_list add_form_scheme="cars"]
    

    This should display Ads list with only the Ads using “cars” form scheme.

    If you want to connect categories to form schemes then you can use the Preselect Ad Category snippet https://github.com/simpliko/wpadverts-snippets/blob/master/preselect-ad-category/preselect-ad-category.php. The snippet will do a couple of things:
    – it will allow assigning form schemes to categories from wp-admin / Classifieds / Categories panel
    – in the [adverts_add] the users will need to select a form scheme first and based on the user selection a proper form scheme will load.

    Using the Custom Fields extension you can create a search form scheme (for [adverts_list]) with the “sport discipline” field. If you would like the [adverts_list] to filter by the “sport discipline” on load then this is possible as well but will requires some custom programming.

    Thread Starter snieroda86

    (@snieroda86)

    Unfortunately, nothing works ?? ?? ?? :
    1. [adverts_list add_form_scheme=”cars”] – doesn’t work
    2. https://github.com/simpliko/wpadverts-snippets/blob/master/preselect-ad-category/preselect-ad-category.php – after adding this snippet of code i have fatal error when i.m trying to edit with elementor “Fatal error: Uncaught Error: Call to undefined function adverts_flash()”

    In the second solution I can assigned form schemes to category – it works fine , i can choose and send form also , but posts do not have a category assigned , so i can’t display posts from specific categories.

    Site link: https://www.mygame.com.pl/dodaj-propozycje-sparingu/

    PHP ver: 7.2
    Theme: Astra

    Plugin Author Greg Winiarski

    (@gwin)

    Any chance that using Custom Fields extension you have removed the Category field from all of the [adverts_add] forms? The Category is not visible anywhere when adding an Ad https://www.mygame.com.pl/dodaj-propozycje-sparingu/ so when saving the Advert the category is not being saved.

    Regarding the Elementor, you can make sure the adverts_flash() function is always available by adding the code below in your theme functions.php

    
    add_action( "init", function() {
      include_once ADVERTS_PATH . '/includes/shortcodes.php';
    });
    

    I am not sure however what is causing the error in the first place as i am not familiar with Elementor, i will look into that when i will find some free time.

    I am testing [adverts_list add_form_scheme='cars'] and it filters the Ads correctly for me, if for some reason it does not work for you i would need you to paste here screens from:
    – the form configuration
    – wp-admin / Pages panel from the page where you are using the shortcode
    – also make sure you have in wp-admin / Classifieds panel at least one Advert with the form scheme selected.

    Thread Starter snieroda86

    (@snieroda86)

    Hi,
    Good news ?? . I found a solution . [adverts_list add_form_scheme=’cars’] doesn’t work with Elementor widget “shortcode” . When i used standard text editor widget, it started to work correctly . Thanx for Your help – You are a Man ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display specific content on specific page’ is closed to new replies.