how to use custom loop in the_content filter

the_content is expecting a string, you’ll have to use output buffering: function my_custom_loop() { $taxonomy = ‘state_cat’; $terms = get_the_terms($post->ID, $taxonomy); if ($terms && ! is_wp_error($terms)) : $terms_array = array(); foreach ($terms as $term) { $terms_array[] = $term->slug; } $have_you_read_query = new WP_Query( array( ‘posts_per_page’ => 100, ‘post_type’ => ‘post’, ‘post__not_in’ => array($post->ID), ‘category__not_in’ => … Read more

Two loops in one function

There’s no need to set up a new query, just use the first one. Replace: $loop = new WP_Query( $args2 ); while ( $loop->have_posts() ) { $loop->the_post(); …with: $firstloop->rewind_posts(); while ( $firstloop->have_posts() ) { $firstloop->the_post(); Update: Missed a few other bugs in your code, here’s the complete rework: function new_function() { $args = array( ‘post_type’ … Read more

Getting posts from multiple users?

First of all, I suggest don’t use query_posts. (No one is really a WPSE user if had no read this answer). So you can use WP_Query with author__in parameter in combination with array_keys PHP function. $paged = get_query_var( ‘paged’ ) ? get_query_var( ‘paged’ ) : 1; $query = new WP_Query( array( ‘author__in’ => array_keys( $following … Read more

Loop through all posts, show attachment if there

You can’t use the_title() as you haven’t set up the post data. Instead for the title you need to use: $post->post_title; To get the attachments you can then use get_children() something like this: $args = array( ‘numberposts’ => 1, ‘post_parent’ => $post->ID, ‘post_type’ => ‘attachment’ ); $attachments = get_children( $args ); foreach($attachments as $attachment) { … Read more

Order by multiple meta keys on wordpress

I don’t understand why can’t you use the post_date of the custom post type which includes date and time together? $arg = array( ‘post_type’ => ‘custom_post_type’, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’) $result = get_posts($args);

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