Display Recent Posts in BuddyPress Profile

This is quite easy, because you can use author as a parameter with get_posts(). The following snippet retrieves the 5 latest posts by a specific user, whose ID you need to pass. $author_ID = bp_displayed_user_id(); $author_posts = get_posts(‘author=”.$author_ID.”&posts_per_page=5′ ); if($author_posts) { foreach ($author_posts as $author_post) { // do output like echo $author_post->post_title.'<br />’ } }

Custom Post type Query post is not working

As of @cybmeta word’s, I answered my question here. Thank you for all of your effort. In future, if someone comes to read this article, just remember, default arguments also affecting your results. So my final working code it. global $post, $paged, $current_user; get_currentuserinfo(); if(empty($paged)) $paged = 1; $args = array( ‘post_type’ => ‘tickets’, ‘post_author’ … Read more

Group by custom field value (start and end times)

try this wich first stack all posts with same times $tabEvent = []; foreach ( $rand_posts as $post ) { setup_postdata( $post ); $start_time = get_field(“start_time”); $end_time = get_field(“end_time”); $index = “$start_time|$end_time”; // store all the posts with same times if (!isset($tabEvent[$index])) { $tabEvent[$index] = []; } $tabEvent[$index][] = $post; } foreach ($tabEvent as $index … Read more

wp json api – get posts by category

I solved the problem in a different way. First I extracted all the posts by including category name inside of it. Check the answer below. public function module_data() { global $json_api; $url = parse_url($_SERVER[‘REQUEST_URI’]); $defaults = array( ‘ignore_sticky_posts’ => true, ‘posts_per_page’ => -1, ‘order_by’ => ‘date’, ‘order’ => ‘ASC’ ); $query = wp_parse_args($url[‘query’]); unset($query[‘json’]); unset($query[‘post_status’]); … Read more

How to get post with slug and exclude categories

Please read this Codex page why you should not use query_posts(). If you really want to use query_posts(): query_posts( ‘name’ => ‘test’, ‘category’ => ‘-15’ // notice “minus 15” ); The right way to exclude category: $query = new WP_Query( array( ‘name’ => ‘test’, ‘category__not_in’ => array(15) ) ); if ( $query->have_posts() ) { ….. … Read more

WordPress Random post (last 3 days posts)

You can use this code for show last 3 days post. Best of luck… $args = array( ‘post_status’ => ‘publish’, ‘type’ => ‘news’, ‘posts_per_page’ => 2, ‘order’ => ‘rand’, ‘date_query’ => array( array( ‘after’ => ‘3 days ago’ ) ) );

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