Support

Account

Home Forums General Issues Attempting to run a query on current page's ID and post_object field of another

Unread

Attempting to run a query on current page's ID and post_object field of another

  • Basically, I have one post type called ‘careers’ and another called ‘locations’. I am trying to run a query a Locations page to display all careers that have been selected for that location via a custom field with the ‘Post Object’ field type selected, with the post_object object set to return an ID, not an object. It is not working. Returning nothing at all. I ran this query using another custom field and hardcoding an example of the value a few posts had an that returned without issue.

    Below is my code.

    ` <?php

    // args
    $args = array(
    ‘numberposts’ => -1,
    ‘post_type’ => ‘careers’,
    ‘meta_key’ => ‘location’,
    ‘meta_value’ => ‘”‘.get_the_ID().'”‘,
    ‘compare’ => ‘LIKE’
    );

    // query
    $the_query = new WP_Query( $args );

    ?>
    <?php if( $the_query->have_posts() ): ?>
    <ul>
    <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <li>
    <a href=”<?php the_permalink(); ?>”>

    <?php the_title(); ?>
    </a>
    </li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>

    <?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>`

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.