• Creator
    Topic
  • #30795
    Resolved info@insigniacreative.co.uk
    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #30804
    Long 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

    Thanks Long

    Works a treat

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