Sub query in a view

Support MB Views Sub query in a view

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #35311
    Jim HunterJim Hunter
    Participant

    I am working with a plugin that I use to sell tickets. It creates a post entry for the ticket, then adds more post entries for each custom field I collect data for and it sets the post_parent to the ticket ID. In a view, I can query the post table, and display the tickets sold, but when I try and get the field data via another query, I can't seem to get the post.ID from the outer loop into my args for the inner query. I have tried a few ways, but I get nothing, yet I know there is data in the database. Here is what I have tried:

    {% for post in menuitems %}
    	{{ post.first_name }} {{ post.last_name }} {{ post.tc_ff_wouldyouconsideryourself_tcfn_4309 }} {{ post.owner_email }}<br />
        {% set theID = post.ID %}
    	{% set args2 = {
            post_type : 'tc_form_fields',
    		post_parent : post.ID ,
        	} 
    	%}
    
        {% set form_fields = mb.get_posts( args2 ) %}
    	
        {% for field in form_fields %}	
            &nbsp;&nbsp;&nbsp;
            {{ field.post_title }}: {{ field.post_content }}<br />
        {% endfor %}
    {% endfor %}
    

    The second query gets nothing. I have also tried {{ post.ID }} and that actually trows an error. I have also tried to create a variable in the outer loop (it's still in the code), and pass the variable to args2, still did not work.

    What am I missing?

    #35331
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can try to print out post ID and other field values to check if it works correctly to troubleshoot the issue. The inner query is working as well on my site. Here is an example
    https://support.metabox.io/topic/traversing-multiple-related-cpts/

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