Custom select query two tables by a meta key

First of all you are trying to combine both of the tables by post_parent. $wpdb->posts.post_parent = $wpdb->ftcalendar_events.post_parent I guess data in the ftcalendar_events has children of posts table, try $wpdb->posts.ID = $wpdb->ftcalendar_events.post_parent Also you can try joining tables: SELECT * FROM $wpdb->posts JOIN $wpdb->ftcalendar_events ON $wpdb->posts.ID = $wpdb->ftcalendar_events.post_parent WHERE $wpdb->posts.post_status=”publish” AND $wpdb->posts.post_type=”post” ORDER BY $wpdb->posts.post_date … Read more

Limit tags shown in post

$count is just an arbitrary variable name. If you’re using a separate loop to get tags and stop after a certain number (as shown on https://codex.wordpress.org/Function_Reference/get_the_tags), replace the $count variable in that example code with something like $tag_count or $counting or $treebark, and it won’t mess up your use of $count in the posts Loop … Read more

How to get thumbnail with pure PHP in a WordPress database?

Okay, a couple of things – first I would suggest modifying your main query to grab the thumbnail ID at the same time (I have also changed it to only get posts that have a thumb): $sql = “SELECT wp_posts.*, meta_value AS thumbnail_id FROM wp_posts ” . “LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id ” … Read more

Loop through incrementing custom fields

How can I loop through the fields and display the content without having to deplicate it? This for loop will cycle through the four field names to avoid duplication. <?php for ($i=1; $i<=4; $i++) { $fieldName=”featured_content_” . $i; $featuredContentPostID = get_field($fieldName)->ID; $selectedFeaturedContent = get_post( $featuredContentPostID ); ?> <li> <a href=”https://wordpress.stackexchange.com/questions/204839/<?php echo esc_url( get_permalink($featuredContentPostID) ); ?>”> … Read more

Get previous posts list

Did you chceck the Codex Date Parameters ? Expecially the ‘before’ param.It works like this: $date = get_the_date(‘Y-m-d H:i:s’); $args = array( ‘date_query’ => array( array( ‘before’ => $date ), ), ‘posts_per_page’ => 10, ); $query = new WP_Query( $args );

wp_posts query slowing down my website

Although a quarter of second is quite slow to query a single post from db, I’m convinced that this is not your only issue. I also use the Query Monitor plugin, but I have never really taken note when does the plugin redline a query as being slow. But that is not the point here. … Read more