Get number of posts in each category since last visit

use wpdb query instead: “SELECT DISTINCT wposts.* FROM $wpdb->posts wposts LEFT JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE post_date >= {$lastvisit} AND $wpdb->term_taxonomy.taxonomy = ‘category’ “; I did not test this but should work. I also suggest you to use … Read more

Better way to query posts?

Since the queries are not related to each other, there is no other way around it. You are going to end with with many queries and slow page (when it is not cached) on a site with many categories. A better approch may be to show latest 50 posts, and display them by category, but … Read more

Why does ‘meta_key’ return an empty array in get_pages

I’m not sure if this is still true, but i tried this one time and found a similar question: Understand this is not my answer, but what i found that ended up working. It was a year ago, and I haven’t tried if querying by meta_key works yet… From this question: https://stackoverflow.com/questions/32104826/wordpress-get-pages-meta-key-dont-show-page This is the … Read more

get_posts – check if custom field has content?

Try this: $args2 = array ( ‘numberposts’ => -1, ‘post_type’ => ‘houses’ ); $custom_posts2 = get_posts($args2); foreach ( $custom_posts2 as $custom_post2 ) { // check here if custom post type opjects custom field “sz_website” has content $sz_website = get_post_meta( $custom_post2->ID, ‘sz_website’, true ); if ( !empty ($sz_website)) { echo ‘<div class=”wpcf7-list-item-field”>’ . $sz_website . ‘</div>’; … Read more

Custom Category widget

Original Code Sample Removed, updated based on new answer: Honestly this doesn’t change too much, other than makes it a bit more succinct, and I’ll explain the major points of what I’ve done. You reuse this code sample a lot: <li class=”cat-item”><a href=”https://wordpress.stackexchange.com/questions/295287/<?php echo get_category_link($cat->term_id); ?>”><?php echo $cat->name; ?></a><span class=”post_count”><?php echo ” ($cat_posts->found_posts+$cat_probs->found_posts)”; ?></span> Inline, … Read more

get the_content by ID and save the result to one array

You can use get_the_content() to fetch the post content, e.g.: $content = get_the_content( $post_id ); Then you can pass it through the_content filter and json encode However, based on your comments, it looks like you’re creating an endpoint for AJAX calls that returns post content. Don’t bother! WordPress comes with one out of the box! … Read more

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