• Resolved zacsto

    (@zacsto)


    I’m using WPAdverts with the Maps and Locations add-on and have also added the Dependant Taxonomy Dropdown snippet from Github. I have entered my own information in to the Location taxonomy area with a three level hierarchy. When selecting a Location in the Advert Add form (user side) the dropdown works exactly as intended. However when viewing the add after being submitted (user side) the Location shows as a number instead of text/hyperlinks. Also when viewing a submitted ad in the admin area the Location area only shows a loading symbol but will never display the information or allow a selection. Editing on the user side again display the dropdown correctly.

    If I turn off the Dependent Taxonomy Dropdown plugin everything works on both the admin and user sides as intended but I plan to have too many options for this to be effective without the dropdown selection method.

    Any help would be appreciated. Also could be noted that I can use a three level hierarchy with the advert-category taxonomy with the Dependent Taxonomy Dropdown plugin and everything works as it should.

    Thanks

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

    (@gwin)

    Hi,
    hmm i would need some more details. Do you have the DTD snippet configured to work with advert_location taxonomy (instead of the advert_category taxonomy)?

    Also is it possible for you to paste here a link to the page where you are having this problem so i can take a look at it?

    Finally, a screen with your settings in Maps and Locations would be very useful, thanks.

    Thread Starter zacsto

    (@zacsto)

    At the end of the DTD snippet is has the following code which I thought was adding in the advert_location functionality. I also tried swapping out all the advert_category for adverts_location but it broke the DTD plugin. FYI, I’m not a web developer but more a change something and see what happens.

    add_filter( "adverts_form_load", function( $form ) {
        if( $form["name"] != "advert" ) {
            return $form;
        }
        
        foreach( $form["field"] as $key => $field ) {
            if( $field["name"] === "adverts_location" ) {
                $form["field"][$key]["type"] = "adverts_field_select_dependant";
                $form["field"][$key]["options_callback"] = null;
                $form["field"][$key]["options"] = array();
                $form["field"][$key]["dtd_use_taxonomy"] = "advert_location";
            }
        }
        
        return $form;
    }, 9000 );

    The problems I’m having are both in the frontend area and in the admin area. I’d be happy to give you an admin account but I’d rather not post it on the open web if there’s another way to send it to you…

    Screenshot of the Add Listing Page showing dropdown working

    View post on imgur.com

    Screenshot of Preview Listing showing numbers for location

    View post on imgur.com

    Screenshot of admin area showing loading symbol

    View post on imgur.com

    Screenshot of DTD off and Location showing correctly

    View post on imgur.com

    I’ve tried all MAL settings but here’s the one that makes the most sense to me.

    View post on imgur.com

    Plugin Author Greg Winiarski

    (@gwin)

    To make this snippet work with advert_location taxonomy you would additionally need to add in your theme functions.php file the code below

    
    
    ###############
    
    add_action( "save_post_advert", "my_mal_save_advert", 10, 3 );
    function my_mal_save_advert( $post_ID, $post, $update ) {
            
        if( !isset( $_POST ) || empty( $_POST ) ) {
            return;
        }
    
        if( isset( $_POST['adverts_location'] ) ) {
            
            if( ! empty( $_POST['adverts_location'] ) ) {
                $location = array( intval( $_POST['adverts_location'] ) );
            } else {
                $location = null;
            }
            wp_set_post_terms( $post_ID, $location, 'advert_location' );
        }
        
        
    }
    add_action( "admin_footer", function() {
        ?>
    <script type="text/javascript">
        if( typeof adverts_frontend_lang === 'undefined' ) {
            var adverts_frontend_lang = { ajaxurl: '<?php echo admin_url( 'admin-ajax.php' ) ?>' };
        }
    </script>
        <?php
    });
    

    Also in dependant-taxonomy-dropdown.php replace line 75 that is

    
        if( isset( $field["value"][0] ) ) {
    

    replace with

    
        if( is_array( $field["value"] ) && isset( $field["value"][0] ) ) {
    

    Finally, in MAL settings in field ‘Location Field’ select ‘Dropdown filed with Location taxonomy.’

    Thread Starter zacsto

    (@zacsto)

    Thank you very much! Everything is working great now!

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

The topic ‘Location Dropdown Selection with Dependent Taxonomy Dropdown Plugin’ is closed to new replies.