Get post ID

Support MB Views Get post IDResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #30795
    info@insigniacreative.co.uk[email protected]
    Participant

    Hi we are trying to build a view that has a query to products the thing is we need to include the current post ID in the meta query this is what we have but can't get it to work if we manually set the ID(producer) then it works any ideas.

    <div class="rn-gallery">
        {% for clone in post.gallery %}
        <img src="{{ clone.image.medium.url }}" width="{{ clone.image.medium.width }}" height="{{ clone.image.medium.height }}" alt="{{ clone.image.medium.alt }}">
        {% endfor %}
    </div>
    
    {% set the_post_id = mb.get_pid() %}
    {% set producer = mb.get_post( the_post_id ) %}
    
    <div class="gb-grid-wrapper gb-grid-wrapper-ca9e7987">
    {% set args = { post_type: 'product', posts_per_page: 1, meta_query: [ { key: 'product_producer', value: 'producer' } ] } %}
        {% set posts = mb.get_posts( args ) %}
        {% for post in posts %}
        {{ mb.get_the_post_thumbnail( post.ID, 'medium' ) }}
        {{mb.get_the_title( post.ID )}}
            {% endfor %}
            </a>
        </div>    

    Thanks Al

    #30804
    Long NguyenLong Nguyen
    Moderator

    Hi,

    To pass the current post ID to the variable args, you can use your variable the_post_id or use the current object post.ID. And you should use another name for custom post object to separate with the current post object. For example

    {% set args = { post_type: 'product', posts_per_page: 1, meta_query: [ { key: 'product_producer', value: the_post_id } ] } %}
    {% set args = { post_type: 'product', posts_per_page: 1, meta_query: [ { key: 'product_producer', value: post.ID} ] } %}
    {% set my_posts = mb.get_posts( args ) %}
    {% for my_post in my_posts %}
    #30809
    info@insigniacreative.co.uk[email protected]
    Participant

    Thanks Long

    Works a treat

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.