Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

any ideas why my function print_r $arr with lot of elements, but only retain cat and dog when it comes to print_r $stack? I need to have $arr used outside the function,

function pre_selected_results() {
    $args = array(...)
    $the_query = new WP_Query($args);

    $arr = array("Dog","Cat");

    while ($the_query->have_posts()) : 
        $the_query->the_post();
        $args = array(...)
        $results = wp_get_post_terms(get_the_ID(),'type',$args);  
        foreach ($results as $result){
            $arr[] = $result;   
        } 
    endwhile;
    print_r ($arr);
    return $arr;
};//End of pre_get_results function
$stack = pre_selected_results();
print_r ($stack);

Thanks a lot!

EDIT : my $args in case that helps: for the quey :

$args['tax_query'] = array(
'relation' => 'OR',
 array(
    'taxonomy' => 'category',
    'terms' => $_GET['category'],
    'field' => 'slug',
),
array(
    'taxonomy' => 'genres',
    'terms' => $_GET['genre'],
    'field' => 'slug',
),
array(
    'taxonomy' => 'types',
    'terms' => $_GET['type'],
    'field' => 'slug',
),

);

and for the wp_get_post_term:

$args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'slugs');

thanks again

share|improve this question
    
Looks like because your query has no posts, or posts have no taxonomies assigned. What arguments do you pass to WP_Query and wp_get_post_terms? –  Eugene Manuilov Jan 17 '13 at 7:48
    
No , my query displays lot of posts,using 3 differents taxonomies,and then print_r arr with all the result, but $stack refuse to have those as well...^^ –  daco.marseille Jan 17 '13 at 8:06
1  
If print_r ($arr); at the end of the function shows something else then print_r ($stack); it is probably related to PHP syntax and parameter passing and not to WP –  Mark Kaplun Jan 17 '13 at 8:22

1 Answer 1

Try using:

array_merge( $arr, $results );

Instead of:

foreach ( $results as $result ) {
    $arr[] = $result;   
}
share|improve this answer
    
Would have posted as comment except for code formatting –  bungeshea_ Jan 17 '13 at 9:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.