Custom queries using wp_query for custom post types
-
I created a plugin for a custom post type and am pulling the posts in via wp_query, however I’m wondering if the way I’m handling this is the best option. It’s working as expected so I won’t get into the details but the general file setup to handle this.
1). I created the plugin then set up an includes directory in my custom theme which contains a queries.php file
2). Then Added arequire get_template_directory() . '/inc/queries.php';
in my functions file
3). Then in my queries.php I created a function to handle the WP_Query and run the loop and display my content.
4). I wanted this on page-work.php so in page-work I make a function call to the function I set up in queries.php and now all those custom posts are being displayed in page-work as expected.For example: If I were going to make 3 more custom post types – would I put them into the existing plugin and then create a new function for each post type in the queries file….then just call each function where I need them?
Or could I eliminate the queries file and just write each function directly in the file I need them: so for page-work eliminate the function call and just write the function directly in that file?
I tried to lay this out as clear as possible as I have been wondering about this for a couple days. This is a custom theme dev project for my personal site.
I appreciate any suggestions, Thank you
- The topic ‘Custom queries using wp_query for custom post types’ is closed to new replies.