I'm trying to understand where to use filters and where to use actions.
Suppose I have a query in a plugin, which later add on modules might modify to change the results of the query, thus modifying the arguments.
Would this be an ideal implementation of this concept, or should I be using actions here?
// Function to display list of pages
function get_page_list() {
$pages_args = array(
'post_type' => 'page',
'posts_per_page' => '1'
);
$pages_query = new WP_Query( apply_filters( 'myfilter', $pages_args ) );
if( $pages_query->have_posts() ) {
while ( $pages_query->have_posts() ) : $pages_query->the_post();
echo get_the_title();
endwhile;
// Reset Post Data
wp_reset_postdata();
}
else echo 'no results found';
}
add_action( 'wp_footer', 'get_page_list', 1);
function change_page_to_post( $pages_args ) {
$pages_args = array(
'post_type' => 'post',
'posts_per_page' => '1'
);
return $pages_args;
}
add_filter('myfilter', 'change_page_to_post');