Wordpres Get Template Part Wpassist

get_template_part – Use Cases and Examples

WordPress allows theme developers to manage their templates in many different ways. But certainly, get_template_part is the best version of it. It uses core WordPress functions to find and load a specific PHP file. So, basically it is like PHP include, but on steroids. In this post, we will show you a few use cases […]

Read more get_template_part – Use Cases and Examples

Wordpress Get Post Id By Meta Value

WordPress: Get Post ID by Meta Value

If you are into developing custom themes for WordPress, you probably know how useful it can be to use custom meta fields in your posts. But only adding those fields is not enough. You need custom loops or functions to filter/get your posts using those meta values. In this post, we share with you a […]

Read more WordPress: Get Post ID by Meta Value

[How to] Add New Tags or Taxonomies to WordPress using PHP

function wpassist_insert_terms(){ $ahc = get_term_by(‘name’, ‘American Heroes Channel’, ‘post_tag’); if( !$ahc ){ wp_insert_term( ‘American Heroes Channel’, ‘post_tag’); wp_insert_term( ‘Discovery Channel’, ‘post_tag’); wp_insert_term( ‘Animal Planet’, ‘post_tag’); wp_insert_term( ‘USA Network’, ‘post_tag’); wp_insert_term( ‘Amazon’, ‘post_tag’); wp_insert_term( ‘TNT’, ‘post_tag’); } } add_action( ‘wp_head’, ‘wpassist_insert_terms’ );

Read more [How to] Add New Tags or Taxonomies to WordPress using PHP

MySQL Query to Get a Random Post from WordPress Database

When you are creating a custom loop, generally query_posts or WP_Query is more than enough for the job. But if you want to work on an API project that depends on WordPress tables, then you will need to use custom MySQL queries. Here is a custom MySQL query to get a random post from the […]

Read more MySQL Query to Get a Random Post from WordPress Database

[How to] Display Number of Posts in WordPress

Using WordPress core function wp_count_posts, you can easily display total number of posts. Here is a simple example on how to use this function: <?php $count_posts = wp_count_posts(); $published_posts = $count_posts->publish; echo ‘We published ‘ . $published_posts . ‘ posts until now, and it’s still growing..’; ?> This displays a text output like this; We […]

Read more [How to] Display Number of Posts in WordPress