Posts loop displaying the same post data

Try using WP_Query instead. So the code would be like: <?php $args = array( ‘posts_per_page’ => 5, ‘cat’ => 2, ‘offset’ => 0, ‘order’ => ‘date’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’ ); $post_query = new WP_Query($args); if($post_query->have_posts()) : while($post_query->have_posts()) : $post_query->the_post(); ?> <div><?php the_permalink(); ?></div> <div><?php the_title(); ?></div> <div><?php the_content(); ?></div> <?php endwhile; endif; … Read more

WordPress block editor embeds not working in theme (single.php)

That would be because they’re using oEmbed, not a shortcode. You should use the function the_content() to render the content of a post, as it applies all the things required to make embeds, shortcodes, etc work properly. If for some reason that’s not an option, you can apply the content filter. <?php echo apply_filters( ‘the_content’, … Read more

How to get The Loop working with $wpdb->get_results()

Turns out I didn’t follow the instructions in the manual to the letter: I seem to have declared global $post too early. I don’t entirely see through this but it works fine now using this code: $eventsPosts = $wpdb->get_results($querystr, OBJECT); if ($eventsPosts) { global $post; foreach ($eventsPosts as $post) { setup_postdata($post); the_title(); // or whatever … Read more

get post id using custom filed value

Try something like this $posts = get_posts( array( ‘numberposts’ => -1, ‘meta_key’ => ‘prime’, ‘meta_value’ => ‘yes’ ) ); $post_ids = array(); if ( $posts ) { foreach ( $posts as $post ) { // Push post’s IDs into array array_push( $post_ids, $post->ID ); } } code isn’t tested but it should work. If you … Read more

Exclude post format from get_posts

You just need to set the operator parameter to ‘NOT IN’ (see Codex on tax queries). Untested, but for your purposes: $args = array( ‘post_type’=> ‘post’, ‘post_status’ => ‘publish’, ‘order’ => ‘DESC’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => array( ‘post-format-aside’ ), ‘operator’ => ‘NOT IN’ ) ) );

Both a page loop and posts loop on the same page

Change: foreach ($posts_array as $monster_news) { setup_postdata($monster_news); To: foreach ($posts_array as $post) { setup_postdata($post); It seems setup_postdata() actually doesn’t modify $post itself (which was news to me). PS also loose empty , in array… I am not sure how it actually works for you with that.

Check return value of get_posts

From previous questions, I know you would want optimize your queries. There is no need to change WP_Query into get_posts for perfomance. As I stated in a another post, yes, get_posts() is faster than WP_Query because get_posts() legally breaks pagination, but what get_posts() do can be done with WP_Query. To really understand what get_posts() does, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)