get_comments_number() returns 0

From quick look at the source there seems to be three possibilities: get_post() returned falsy value, so current post context is invalid in some way. $post->comment_count is 0. get_comments_number filter is being used to adjust the output. Most commonly it would be case 1/2 with something interfering with global post context, dump get_post() at the … Read more

What’s wrong with this piece of code? [closed]

This loop: while($listing->have_posts()): get_template_part( ‘partials/listing-cars/listing-list’, ‘loop’ ); endwhile; will never terminate, because $listing->have_posts() will never be false. You need $listing->the_post() to advance the loop to the next post in each iteration. Then, when the last post is reached, $listing->have_posts() will be false and the loop will end. while($listing->have_posts()): $listing->the_post(); get_template_part( ‘partials/listing-cars/listing-list’, ‘loop’ ); endwhile;

Known Issues in WordPress When Upgrading PHP to ver 7

WordPress recommends PHP7 and MariaDB 10.0 or higher, so your core installation should be fine. If you’re using any third-party plugins and/or themes (including ones you’ve written), you would be wise to ensure that they too are compatible with PHP7. Check the respective maintainers’ support streams (either the relevant plugin/theme pages on wordpress.org or the … Read more

Get the name of menu item with wp_nav_menu

The object_id holds the ID of whatever object the menu item refers to, this will be a post, post etc. The get_queried_object_id() will give you the ID of the current page. $menu_items = wp_get_nav_menu_items( ‘main-menu’ ); $this_item = current( wp_filter_object_list( $menu_items, array( ‘object_id’ => get_queried_object_id() ) ) ); echo $this_item->title;

Displaying list of posts in category page

One option would be to just replace category template with another file from the plugin using category_template filter: function change_category_template( $template ) { $category_template = plugin_dir_path( __FILE__ ) . ‘new-category.php’; return $category_template; } add_filter( ‘category_template’, ‘change_category_template’, 999 ); So, in the new file you could have the structure you want. The main problem is that … Read more

random display categories – change url

As you are concatenating the result to a href you must wrap the ifelse statement inside another set of parentheses so the result is calculated first and then returned: <a href=”‘.(($cat_id == 5) ? esc_url($custom_link) : esc_url($category_link)).'”>

Need help with pagination

$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args_blog = array( ‘post_type’ => ‘post’, ‘paged’ => $paged, ‘posts_per_page’ => get_option(‘posts_per_page ‘) ); $query_blog = new WP_Query( $args_blog ); if($query_blog->have_posts()) : while($query_blog->have_posts()) : $query_blog->the_post(); $big = 999999999; // need an unlikely integer echo paginate_links( array( ‘base’ => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ), ‘format’ … Read more

Filter results from a serialized string to use on statistics

So basically the form saves a large serialized array in the database. Now since you have multiple forms, you need to iterate over the result from get_results, unserialize the column and then access the city key. global $wpdb; $table_name = $wpdb->prefix.’db7_forms’; $results = $wpdb->get_results( “SELECT form_value FROM $table_name WHERE form_post_id = 6062”, OBJECT ); // … Read more