a little direction on custom post type

You’re not using templates correctly. You don’t use a custom page template to output custom posts or a custom post archive. There are dedicated templates you need to create to give your post type its own templates. Refer to the Template Hierarchy. For example, if your post type is called event, you need to create … Read more

Sidebar show posts by current category also in single post

Well, let me first describe the full code in code comments. Please read the comments carefully- // By this below code you are returning TRUE to the filter ‘tve_dash_enqueue_frontend’ filter. Which is I think, is turning something on. add_filter( ‘tve_dash_enqueue_frontend’, ‘__return_true’ ); // Here you are hooking the `widget_posts_args` filter with `my_widget_posts_args` function. add_filter( ‘widget_posts_args’, … Read more

Random posts from a pool of posts

Quick & simple: You could simply use post__in in your query with the post IDs of those in your pool, though it might be less easy to maintain when you add and remove posts. Or you could use a meta field and change your query to include it, see the WP_Query documentation. Then either set … Read more

Removing Extra Caption tag around image on post of WordPress

To make sure the shortcode executes, save the content to a variable, then run do_shortcode on the saved variable. <div class=”thecontent” itemprop=”articleBody”> <?php $content = get_the_content(); echo do_shortcode($content); ?> </div> The difference is, echoing just literally echoes whatever has been grabbed. PHP’s built-in functions don’t have any special way to process shortcodes so they just … Read more

Why are my paginated posts always returning the same results?

Found the culprit. I’d foolishly hard-coded the offset to be 0, which must have been overriding WordPress’ query. I changed: $posts_list = new WP_Query([ ‘posts_per_page’ => 1, ‘offset’ => 0, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘suppress_filters’ => true, ‘paged’ => $paged ]); to: $posts_list = new WP_Query([ ‘posts_per_page’ => 1, ‘orderby’ … Read more

WordPress website loads more posts than expected

The theme is most likely altering the main query via the pre_get_posts hook, chaning the posts_per_page argument to -1 for all posts, or another higher number. You can search your theme folder for pre_get_posts to see all the times this hook is used. A better solution would be to install the Query Monitor. With this … Read more