Add Locality through Jquery

This topic contains 4 replies, has 3 voices, and was last updated by  Stiofan O’Connor 5 years, 9 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #442256

    ian bran
    Expired Member
    Post count: 122

    Hello,
    I want to display locality in a div inside the listing image. Please see screenshot of objective.
    I’ve managed to insert a div (absulte relative to .geodir-post-img thorough Jquery

    
    
    var $newDiv = jQuery("<div/>")   // creates a div element
                     .addClass("comunalisting")   // add a class
                     .html("<span>City Name</span>");
    
        jQuery(".geodir-post-img").append($newDiv);

    The problem is locality is a php variable.

    Is it possible to add this?
    perhaps if I knew the code to the specific locality I could move forward.
    For address is

    
    
    global $wp_query;
        $postid = $wp_query->post->ID; // retrieve the ID
        $address= geodir_get_post_meta($postid,'post_address',true); 
        echo $address;

    but I don’t know just to show the locality

    If there’s a better way it would be great.

    Thank you

    #442297

    Alex Rollin
    Moderator
    Post count: 27815

    You can show the whole address, and then hide the parts you don’t need with CSS.

    https://wpgeodirectory.com/docs/changing-the-layout-of-addresses/

    #442322

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Not tested but u want something like:

    
    
    add_action('geodir_after_badge_on_image','_my_image_city');
    function _my_image_city($post){
    $post_city = isset($post->post_city) ? $post->post_city : geodir_get_post_meta($post->ID,'post_city',true);
    echo "<div class='my-city-name'>$post_city</div>";
    }

    Stiofan

    #442374

    ian bran
    Expired Member
    Post count: 122

    Thank you guys, this worked perfectly!!!!
    Cheers!

    #442379

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Great! 🙂

Viewing 5 posts - 1 through 5 (of 5 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket