Include custom table in query

Working code: <?php global $wpdb; $date = date(“Y-m-d”); $querystr = ” SELECT * FROM wp_posts JOIN wp_ftcalendar_events ON wp_posts.ID = wp_ftcalendar_events.post_parent WHERE wp_posts.post_status=”publish” AND wp_posts.post_type=”post” AND wp_ftcalendar_events.start_datetime >= ‘$date’ ORDER BY wp_ftcalendar_events.start_datetime ASC “; $pageposts = $wpdb->get_results($querystr, OBJECT_K); ?> <?php if ($pageposts): ?> <?php global $post; ?> <?php foreach ($pageposts as $post): ?> <?php setup_postdata($post); … Read more

Run an update query in a function

As David pointed out, wpdb::query() does not allow multiple calls. So yes, it is because of having the “SET @newnum = 0;” before your actual query. This kind of query is simply not possible as the backend prevents that in order to protect against SQL injection attacks. Besides of that, the technique I described in … Read more

WP_Query secondary query failing

Maybe you can try with get_posts() and foreach loop for the second query instead of WP_Query and then you will have something like this: <?php $secondary_query = get_posts(‘category_name=students’); foreach($secondary_query as $secondary_post): echo “<li>” . get_the_title($secondary_post->ID) . “</li>”; endforeach; ?> With above like style you don’t need wp_reset_query() just make sure you pass the post ID … Read more

Query post for today, if no post get the previous one

I think you should make a recursion function that will call itself if there’s no posts found passing new date to query for.. function getDatePosts( $date, $query_args ) { $query_args[‘date_query’] = array( ‘year’ => date( ‘Y’, $date ), ‘mounth’ => date( ‘m’, $date ), ‘day’ => date( ‘d’, $date ) ); $query = new WP_Query( … Read more

Filter posts/pages by user_role array

You’ve used LIKE comparison method, that means every similar expression will be matched, including exact string and similar string. If you want to match exact string, you should use = operator. Example: global $current_user; $user_roles = $current_user->roles; $user_role_query = array(); for ($i=0; $i < sizeof($user_roles); $i++) { $user_role_query[] = array( ‘key’=>’attribution_roles’, ‘value’ => $user_roles[$i], ‘compare’=>’=’ … Read more

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