I have setup a custom post type in Wordpress. It is a section where the client can upload documents in PDF format. The documents are divided into two categories - 'Downloadable Forms' and 'Menu' ; the Custom Field name for the category is 'document_category'
I am trying to run a query and only display the 'Downloadable Forms' on a page. Here is the code I normally use --- I'm hoping someone can help me add what I need to make it work?
<?php
$args = array('post_type' => 'prep_forms', 'posts_per_page' => -1);
// The Query
$the_query = new WP_Query( $args );
// The Loop
$i = 0;
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<li><a href="<?php echo get_field('document_pdf_file'); ?>"><?php the_title(); ?></a></li>
<?php
$i++;
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
Thanks.
Why dont you make it simpler and set a query based on custom field data?
That way any post with custom field key display and custom field value true will be shown on your query.
I've used the
get_fields($post_id = false)
function of the Advanced Custom Fields plugin that returns an array of all the posts' custom fields and then filtered it to match your needs.Hope i've helped
Well, you can use the is_category(); inside loop and only display those posts, like so (using your same code):
Better yet: http://codex.wordpress.org/Function_Reference/is_category
Hope that helps.