How to pull latest posts from a specific category

I figured it out, had a lot of syntax issues and open php tags. <?php // the query $the_query = new WP_Query(array( ‘category_name’ => ‘local-news’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 5, )); ?> <?php if ($the_query->have_posts()) : ?> <?php while ($the_query->have_posts()) : $the_query >the_post(); ?> <div class=”card-body pb-0″> <div class=”latest_news_cont”> <a href=”<?php the_permalink() ?>”> <?php … Read more

Featured Story Shortcode not outputting content

First thing : initialize variable $content=””; before the while loop. other than that your code is right. there is something you are doing wrong to use shortcode. you should check this link https://developer.wordpress.org/reference/functions/do_shortcode/#user-contributed-notes and make changes. also if using for custom post type please add post_type argument in $args

how can sort my column

Your columns are in an array. PHP has a few options you can use depending on how you want to sort the array (low to high, high to low, etc.). Here is the documentation for that. https://www.php.net/manual/en/array.sorting.php

WordPress hide post from custom post-type on a single page

Instead of using the pre_get_posts hook simply modify your WP_Query to fetch posts with certain conditions. $loop = new WP_Query( array( ‘post_type’ => ‘projects’, ‘orderby’ => ‘rand’, ‘posts_per_page’ => 1, ‘meta_query’ => array( array( ‘key’ => ‘your_field_name’, ‘value’ => ‘the_value’ ), ), ) ); This, right from the beginning only fetches the posts that matches … Read more

How to get post image caption by index

I have used function to extract data inside figcaption tags, and $position is stand for the index of the current image. function getImageCaption($postID, $position){ $post_id = $postID; // get the post object $post = get_post( $post_id ); // we need just the content $content = $post->post_content; // we need a expression to match things $regex … Read more