Support

Account

Forum Replies Created

  • I tried another approach – I get all posts and than I filter those that is right into one array and all others into another array. Is in fact better for my purposes. I have this code:

    $arenden = new WP_Query( $args );
    if ( $arenden->have_posts() ) : 
        while ( $arenden->have_posts() ) : $arenden->the_post();
    $utfors_av = get_field('utfors_av');
    $utfors = reset($utfors_av);
    
        if($utfors == $user_id) {
            array_push( $idmina, get_the_ID() );}
        endwhile;
    endif;
    ?>

    The $args is just the standard, $idmina is the array I have setup were I want to store the IDs. But when I use this, I get an error:
    Warning: reset() expects parameter 1 to be array, boolean given in ../archive-arenden.php on line 42 Line 42 is $utfors = reset($utfors_av).

    When I use this on line 42 instead:
    $utfors = strstr($utfors_av, ',', true);
    I get another error saying it is an array.
    Warning: strstr() expects parameter 1 to be string, array given in /home/almewebb/alpnet/wp-content/themes/enterprise-pro/archive-arenden.php on line 42

    So what do I do wrong. Surely something trivial that I don’t see.

  • I am doing this inside a template (archive). I updated my code with WP_Query

       <?php    $user_id = get_current_user_id();
       echo $user_id;?>
        
        <?php $$args = array(
       'post_type' => 'arende',
       'meta_key' => 'utfors_av',
       'post_status'       => 'publish',
       'posts_per_page'    => -1,     
       'order' => 'ASC',
       'meta_query' => array(
           array(
               'key' => 'utfors_av',
               'value' => $user_id, //array
               'compare' => '=',
           )
       )
     );
     $query = new WP_Query($args);;?>

    But this returns the same result as mine did before.

  • Do you have any date set yet? Have project that needs this feature and it would be great not to have to hard code it… 🙂

Viewing 3 posts - 1 through 3 (of 3 total)