Get Sticky Posts From Custom Post Types

If you need to get sticky posts from custom post types then this wp snippet will query only sticky posts from post types you choose. It’s quite simple, all we need to do is pass post__in parameter in get_posts function. Here is code example: $stickyposts = get_posts( array( ‘numberposts’ => 5, ‘post_type’ => array(‘post’,'Portfolio’), ‘post__in’…

Display Post Types With Same WP Page Template

If you need to Display Post Types With Same WP Page Template like “cars”, “accessories” and similar, with same  custom page  template here is snippet to do just that Code: add_filter( ‘template_include’, function( $template ) { $posttypes = array( ‘cars’, ‘accessories’ ); $post_type = get_post_type(); if ( ! in_array( $post_type, $posttypes ) ) return $template;…

Add thumbnail to post automatically

Sometimes we need to add thumbnail to post automatically, here is code written by damian czapewski which you may find useful while building wp theme, wordpress plugin or other. This isn’t copy/paste wp snippet, it’s more just direction of how to do it. Code: $wp_upload_dir = wp_upload_dir(); $fileurl = “http://damianc.pl/th.jpg”; $filename = $upload_dir['path'] . DIRECTORY_SEPARATOR…