• Resolved blazeblaze

    (@blazeblaze)


    Hi

    A pmpro_getMembershipCategories($current_user->ID); function returns an array of names of categories. The names are only simple strings like CategoryName – and nothing more I think.

    array(1) {
    [0]=>
    string(2) “14”
    }

    How to loop through it and display posts that are inside of each category?

    This code doesn’t work:

    if (true) {
        $args = pmpro_getMembershipCategories($current_user->ID);
        $query = new WP_Query($args);
    
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
                ?>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                <?php
            }
            wp_reset_postdata();
        }
    }

    Any hints?

    Regards!

  • The topic ‘How to loop through an array with category names strings to display posts?’ is closed to new replies.