Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Basically the set up I currently have is two sets of custom post types which are:

uc_university and uc_course

I'm having lots of trouble trying to display a course based on a my Advanced Custom Field 'post_object'. I have tried multiple solutions and so far have come up with an example that only allows me to simply display the normal custom post type.

But what I want to do is to limit the custom post types that get displayed by their post_object. Below is where I am up to on my query, but I think I may be going down the wrong route.

I only want to display the post types of uc_course that are linked to the post_object I have set up to uc_university.

<?php
    $args = array(
            'post_type' => 'uc_course',
            'meta_query' => array(
            'relation' => 'OR',
            array(
                'key' => 'uc_university',
                'value' => 'Anglia Ruskin University',
                'compare' => 'NOT LIKE'
            ),
        )
    );
    $query = new WP_Query( $args );
        while ($query->have_posts()) : $query->the_post(); ?>
        <li>
        <a href="<?php the_permalink() ?>"><img src="<?php echo the_field('university_main_image'); ?>" alt="<?php the_title(); ?>Clearing" /></a>
        <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
        <p><?php the_excerpt(); // or the_content(); ?></p>
        </li>

<?php endwhile;wp_reset_postdata(); ?>   

Any help and any ideas would be greatly appreciated! I have attempted all sorts, gone through the WP Codex, but in parts I do not necessarily understand it as meta queries etc do get complicated and I would like some help or help explaining what does what so I'm fully aware of the code.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.