• Resolved segamaze

    (@segamaze)


    Hello,

    I want to combine a directorist listing with posts. So every listing has a few amounts of post combined through the same category slug. Thats not the problem.

    The only problem I have: I want to display some specific information under each post. For example the address of the company.
    How can I display these information depending on base of the same slug category? Is there a snippet I can use in the single.php of the post?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @segamaze,

    That is an interesting question you got there. I do not understand your slug structure properly, but if they have a common slug I think, you can get the specific directory listing for that particular slug, this can be used to get the post_id (found on StackOverFlow, changed the $post_type):

    function get_post_id_by_slug( $slug, $post_type = "at_biz_dir" ) {
        $query = new WP_Query(
            array(
                'name'   => $slug,
                'post_type'   => $post_type,
                'numberposts' => 1,
                'fields'      => 'ids',
            ) );
        $posts = $query->get_posts();
        return array_shift( $posts );
    }

    And then you can use the get_post_meta function to get the value you wanted, for example, Address set on a specific listing:

    
    get_post_meta( $post_id, $key = '_address', $single = true );
    

    This should give you an idea of how to achieve what you’re looking for. I can’t say anything conclusive unless I see the structure you got on your site. In any case, I hope this helps, let me know if you need help with anything else or this.

    Regards,
    Mahdi.

    • This reply was modified 2 years, 12 months ago by Mahdi.
    • This reply was modified 2 years, 12 months ago by Mahdi.
    • This reply was modified 2 years, 12 months ago by Mahdi.
    Thread Starter segamaze

    (@segamaze)

    Hello Mahdi,

    that’s exactly what I was looking for, thank you!
    Just two little things that are absolutely optional: Is there a shortcode to display the whole contact section like on the single listing site?
    And is there a shortcode for the header slider I could use? For example as an additonal slider/gallery or instead the default post header.

    Thank you

    Hi @segamaze,

    I’m sorry, no, there’s no shortcode for that.

    Regards,
    Mahdi.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display specific listing information on single post site’ is closed to new replies.