Unexpected end of file

You arent closing your if tag: $tags = wp_get_post_tags($post->ID); if ($tags) { echo ‘Related Posts’; $first_tag = $tags[0]->term_id; $args_related = array( ‘tag__in’ => array($first_tag), ‘post__not_in’ => array($post->ID), ‘posts_per_page’ => 10, ‘caller_get_posts’ => 1 ); $related_articles_query = new WP_Query($args_related); }

WP Query Category Atribute Not Working

Instead of get_posts, why don’t you use WP_Query instead? I removed a few arguments because they are the default and can be omitted. $args = array( ‘posts_per_page’ => 3, ‘category_name’ => ‘blogue’, ‘suppress_filters’ => true, ); $wqBlog = new WP_Query($args); And in your HTML <?php if( $wpBlog->have_posts() ): ?> <section class=”container”> <div class=”cards display–flex “> … Read more

difference between like ‘%%%var%%’ and ‘%var%’

Firtly, in SQL the % symbol is a “wildcard operator”. When used in a LIKE statement, it means “0 or more characters”. So LIKE ‘Hello%’ means any string beginning with Hello, including just Hello. While LIKE ‘%Hello%’ means any string that contains Hello, either at the beginning, middle, or end. $wpdb->prepare() on the other hand … Read more

Get number of authors

This reply was pretty low on the list, on the article you referred to; but it will do the job: $users_count = count(get_users(array(‘fields’=>array(‘ID’),’role’=>’author’))); Originally posted here, buy shanebp

How to use offset in WP_Query

offset is one of the arguments that you can pass to WP_Query, so it belongs in the $args array: $args = array( ‘post_type’ => ‘post’, ‘category_name’ => ‘category’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘showposts’ => 4, ‘offset’ => 4, ); PS: $wp_query is a reserved variable used by the main query. When creating your … Read more

List posts in a given category

You are already passing category in $args. so not need to use get_categories(). You can use below code. $args = array( ‘cat’ => 5, ‘posts_per_page’ => -1, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ); $custom_loop = new WP_Query($args); if ($custom_loop->have_posts()) { echo “<ul>”; while ($custom_loop->have_posts()) { $custom_loop->the_post(); echo ‘<li><a href=”‘ . get_permalink() . ‘”>’ . … Read more