Custom Query Function
-
Hi out there,
I want to display my custom post types on a custom page template with adding the query from the functions.php.
I’ve created a page template with a normal loop like this:
<?php while ( have_posts() ) : the_post(); ?><?php the_title(); ?><?php endwhile; ?>
and in my functions.php I added this:function default_work_query( $wp_query ) { if ($wp_query->is_page('movies')) { $wp_query->set('post_type', 'movies'); } return $wp_query; } add_action('pre_get_posts', 'default_work_query');
unfortunately the output is 404.
I let print me out the $wpquery before the if and he gives me 2 queries one with the page id content and one in this one with my wanted arguments. Has anyone an idea how to fix this?
I need to do this from the functions.php!!!Have a nice day, thank you.
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Custom Query Function’ is closed to new replies.