Uses of get_posts() function in WordPress

WordPress is really a great CMS for current users. WordPress developers use lots of functions and codes to customize WordPress theme and Plugins. Some developers use custom post type of shows testimonial, Products, Services or other things. So they use core functionality WordPress. In this case they use get_posts () function to get the posts of custom post type or blog posts.

We can use this function in any template of WordPress or in any file of WordPress. So it’s not necessary to use this function in any template.

It is useful for the following criteria:

If you want to show all posts then just pass -1 in place of posts number. ‘posts_per_page’   => -1. But through passing any number you can control the posts number in one page.

If you want to get posts according to category  then you can use this just passing an array of category id. But if you have not lots of categories and want to show the posts of just one category then just pass the category ID and it will return then posts of that certain category. You can get category ID using taxonomy function in any page or template. If you want to create any template for specific category then please show the Template Structure to create file for any certain category.

Category-slug.php, category-ID.php and category.php are specific files for these.

Orderby and order are 2 argument in thin function. You can set order by value through passing the value of this argument.  For random posts you just need to pass rand in orderby.

Order have 2 values DESC and ASC.

If you want to include an specific posts in array then pass array of include posts but if you want to exclude any post then exclude is also exists in get_posts.

Post_type is default post  but you can pass any custom post type if you have created.

get_posts() return a set of array according to entered parameters.

For the further information you can check the WordPress tutorial.

 

$posts_array = get_posts( $args );  
 $args = array(

                'posts_per_page'   => 5,

                'offset'           => 0,

                'category'         => '',

                'orderby'          => 'post_date',

                'order'            => 'DESC',

                'include'          => '',

                'exclude'          => '',

                'meta_key'         => '',

                'meta_value'       => '',

                'post_type'        => 'post',

                'post_mime_type'   => '',

                'post_parent'      => '',

                'post_status'      => 'publish',

                'suppress_filters' => true ); 

Footer in Genesis Freamework of WordPress

Sometimes you need to do to following things with footer:
1. Need to remove footer support from theme
2. Need to remove footer
3. Need to add custom footer HTML
So here is an example to for all above option.

1. Need to remove footer support from theme

/** Remove footer widgets support from theme */
remove_theme_support( 'genesis-footer-widgets', 3 );

2. Need to remove footer

/** Remove Footer */
remove_action( 'genesis_footer', 'genesis_do_footer' );

3. Need to add custom footer HTML

remove_action( 'genesis_footer', 'genesis_do_footer' );
add_action( 'genesis_footer', 'custom_footer_html' );
/**
 * Custom Footer HTML.
 */
function custom_footer_html() { ?>

	<div>
		 <!-- Your Copyright text goes here -->
	</div>
<?php } ?>