WordPress.org

Ready to get started?Download WordPress

Forums

Getting IDs without printing them? (2 posts)

  1. Southbound
    Member
    Posted 5 years ago #

    There's something wrong in this code:

    $myQuery = new WP_Query();
    $myQuery->query('post_type=page&meta_key=mood&meta_value=frustrated');
    $myArray = array();
    while ($myQuery->have_posts())
    {
    the_post();
    global $post;
    $myArray[] = $post->ID;
    }
    echo count($myArray);

    On the last line in the while block, I get this error:

    Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 35 bytes)

  2. Southbound
    Member
    Posted 5 years ago #

    Found it myself.

    the_post();

    should be

    $myQuery->the_post();

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.