In front-page.php I want to show only pages/posts with a particular custom field
-
Hi,
I’m trying to set up my front-page.php template so that only content (posts or pages) with a custom field which matches “front_page_order” exists, and further it’s ordered by a a numeric value of the custom field.
I’ve tried many examples I’ve found as well as the documentation for WP_Query and WP_Meta_Query and nothing works as expected. Too many results are returned so it feels like the query is not working
Here’s one variation of the many attempts I’ve tried:
<?php get_header(); ?> <h1>Home page</h1> <?php if ( have_posts() ) : ?> <?php $args = array( 'post_type' => 'any', 'meta_key' => 'front_page_order', 'orderby' => 'meta_value_num', 'order' => 'ASC' ); $pages = new WP_Query( $args ); foreach( $pages as $page ) { ?> <article> <h1><?php echo $page->ID; ?></h1> </article> <?php } ?> <?php endif ?> <?php get_footer(); ?>
Any help would be appreciated, this has been stumping me for hours.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘In front-page.php I want to show only pages/posts with a particular custom field’ is closed to new replies.