Last active
December 2, 2015 03:52
-
-
Save rabidgadfly/d154d97b55fa9a1e1e90 to your computer and use it in GitHub Desktop.
WordPress page template to display posts of a specific post type filtered by the id of an Advanced Custom Field 'Field Object'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * WordPress Page Template: Project Listing | |
| */ | |
| ?> | |
| <?php get_header(); ?> | |
| <div id="container"> | |
| <div id="content"> | |
| <?php | |
| $org = ck_get_current_organization(); // custom function to retrieve logged-in user's organization object | |
| $oid = $org->organization_id; // ID of logged in user's organization | |
| $type = 'project'; // custom post type of 'project' | |
| $args=array( | |
| 'post_type' => $type, | |
| 'post_status' => 'publish', | |
| 'posts_per_page' => -1, | |
| 'meta_query' => array( | |
| array( | |
| 'key' => 'organization', // ACF custom field of type 'field object' | |
| 'value' => $oid, // matches the id of the field object | |
| 'compare' => '=' | |
| ) | |
| ) | |
| //'caller_get_posts'=> 1, | |
| //'category_name' => 'my-town' | |
| //'tag' => 'whatever' | |
| ); | |
| $my_query = new WP_Query($args); | |
| if( $my_query->have_posts() ) { | |
| while ($my_query->have_posts()) : $my_query->the_post(); ?> | |
| <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> | |
| <?php | |
| endwhile; | |
| } | |
| wp_reset_query(); // Restore global post data stomped by the_post(). | |
| ?> | |
| </div><!-- #content --> | |
| </div><!-- #container --> | |
| <?php get_sidebar(); ?> | |
| <?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment