Related type & WP_Query

50 views
Skip to first unread message

Ludovic

unread,
Mar 9, 2013, 5:18:20 AM3/9/13
to magic-...@googlegroups.com
Hello everyone,
i have a group called "contenu_1" and in this group, 2 related type fields ("contenu_1_selectionner_larticle" & "contenu_1_selectionner_lactivite") which can be duplicated. The related types fields should retrieve the number of the related post so that i could use wp_query to display the tittle of each one. But infortunately, this retrieve only the first post title, but not the one in the second wp_query.

This is the code :

<?php
$values = get_group('contenu_1');
foreach($values as $value){
    // The Query
    $the_query = new WP_Query( 'p=' . $value['contenu_1_selectionner_larticle'][1] );
    // The Loop
    while ( $the_query->have_posts() ) :
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    endwhile;
    // Restore original Post Data
    wp_reset_postdata();
    
    /* The 2nd Query (without global var) */
    $query2 = new WP_Query( 'p=' . $value['contenu_1_selectionner_lactivite'][1] );
    // The 2nd Loop
    while( $query2->have_posts() ):
        $query2->next_post();
        echo '<li>' . get_the_title( $query2->post->ID ) . '</li>';
    endwhile;
    // Restore original Post Data
    wp_reset_postdata();
    }
?>


Anyone could advice me. Thanks !

Ludovic

unread,
Mar 9, 2013, 5:50:59 AM3/9/13
to magic-...@googlegroups.com
I also noticed that, if i create a second group, with several related fields, only the first custom field is retrieved. I think it's what happens in my above code.

Ludovic

unread,
Mar 9, 2013, 8:27:37 AM3/9/13
to magic-...@googlegroups.com
So in fact, i can't display another post type than articles in a related_type field. If  i choose a custom post type that i've created, it just doesn't display anything.
Has someone managed to retrieve a post from a custom post type in related-type field ?

Ludovic

unread,
Mar 10, 2013, 3:26:56 PM3/10/13
to magic-...@googlegroups.com
However, when i do "the_meta()" request, i can see the values of the custom fields created.

Ludovic

unread,
Mar 14, 2013, 4:34:50 AM3/14/13
to magic-...@googlegroups.com
Even related types fields from a custom post type appear with "the_meta()" but i can't call it into a wp_query ... Has someone got the problem ?
Reply all
Reply to author
Forward
0 new messages