Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: array_intersect

  1. #1
    New Coder
    Join Date
    Feb 2011
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    array_intersect

    I have a wordpress site where id like to compare 2 arrays. My problem is that one array is in the header.php and the other is in the footer.php. These 2 .php-pages are the once which construct the page you visit, so in my head the should be accessible?

    when i try to intersect the arrays in the footer i get
    Argument #1 is not an array in footer.php .

    this is the code in header.php
    This puts all categories from all the posts in in myQuery and puts them in
    $categoriesOverview

    PHP Code:
        <?php $myQuery = new WP_Query(array('showposts' => -1'post_type' => ('artiklar')));

    $categoriesOverview = array();
    while( 
    $myQuery->have_posts() ) : 
    $myQuery->the_post();
    foreach( 
    get_the_category() as $cat ) {
    $categoriesOverview[] = $cat->name  ;
                                } 
                                
    ?>
    footer.php

    PHP Code:
    while( $myQuery->have_posts() ) : $myQuery->the_post();
    $categoriesArchive = array();
    foreach( 
    get_the_category() as $cat ) {
    $categoriesArchive[] = $cat->name  ;
    }
    $result array_intersect($categoriesOverwiev$categoriesArchive);
    echo 
    $result

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    This looks like it has a typo to me: $result = array_intersect($categoriesOverwiev, $categoriesArchive);. You probably do not have a $categoriesOverwiev variable.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •