[resolved] Show child posts from a certain post type wich is child to another (7 posts)

  1. romuloctba
    Posted 4 years ago #

    Hey guys
    Ive triyng and researching a lot, but cant find a solution to this:
    created (using types plugin) a post type named discografia.
    then, another one, which i assigned as child from dicografia, named musica.

    What i want is to display every musica child from a discografia.
    Discografia shows itself like this:

    $newsArgs = array( 'post_type' => 'discografia', 'posts_per_page' => 6);
        $newsLoop = new WP_Query( $newsArgs );
       while ( $newsLoop->have_posts() ) : $newsLoop->the_post();              
    <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>

    (is a little more full of markup, but nothing unusual - just shoing thumbs and custom fields)

    For testing purposes, i checked if every post shown has its id ok and save it in a variable

    <?php $post_ied = get_the_ID(); 
    echo $post_ied;

    it worked fine.

    Now, i need to show musicas in every discografia listed above, i used snippet found on http://snipplr.com/view/62428/

    i changed some variable names, so it dont fight with those i created before... lol

    <?php $loope = new WP_Query( array( 'post_type' => 'musica', 'post_parent' => $post->ID, 'posts_per_page' => 30, 'order' => 'ASC' ) ); ?>
                                        <?php while ( $loope->have_posts() ) : $loope->the_post(); ?>
                                                  <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php endwhile; ?>

    And it works. EXCEPT that it shows all musicas for every post from discografia, not only for its parents... got that?

    i mean musica "MUSICA1" apears for both discografia "DISC1" and "DISC2", but it is child of DISC1 only

    I tried puting post->ID into a variable, but, even thou it work, it appears that 'post_parent = something' ist working =/

    Thnx a lot, i make lots of consults here , all the time, really, but this one i couldnt find the awnser...

  2. romuloctba
    Posted 4 years ago #

    I really need a hand on this, but i think awnser is pretty difficult.. the only way i found was trought views plugin, but it is a premium plugin wich i wont afford =/

  3. Amir Helzer
    Posted 4 years ago #

    Have a look here:

    Scroll to the bottom. I've added a section for how to load child items with Types API.

    Don't worry about not being able to buy Views. You can still help Types project:
    * Rate it here on wordpress.org
    * Write about it in your blog
    * Tell your friends about Types

  4. romuloctba
    Posted 4 years ago #

    AlmirHelzer, thats simply beautifull!
    I was searching for a hole day for the solution, and couldnt find it! is not a common thing paginate google looking for awnsers. Normaly mine come on the first page. This one, thou, made me go realy far =P

    What u guys do with types plugin is amazing, it really comes handy with post types and custom fields. Lol, i can imagine if i manually created them... all those arrays would make me sick lol

    Btw i think that making views paid is really fair. I estimate it would save me at least 30% of the time spent on a average site's development.

    thanks a lot! Really! those lines shall get me trough it

  5. romuloctba
    Posted 4 years ago #

    Almir, let me ask you something: is there anywhere where i can find the codes i can use with types api?

  6. Amir Helzer
    Posted 4 years ago #

  7. romuloctba
    Posted 4 years ago #

    actually, no, i havent seen it :P

    now i am, thanks a lot.

Topic Closed

This topic has been closed to new replies.

About this Topic