How to show related posts by category

The question has already been asked and the answer has been posted too, How to display related posts from same category? Add this code inside your single.php after a loop wherever you want to show related post, <?php $related = get_posts( array( ‘category__in’ => wp_get_post_categories($post->ID), ‘numberposts’ => 5, ‘post__not_in’ => array($post->ID) ) ); if( $related … Read more

Get current menu_order

If you have the post with an $id: $thispost = get_post($id); $menu_order = $thispost->menu_order; WordPress itself does not provide a function to get the menu_order, so you have to query the post-Object. If you are outside the loop, you can use the above function, however inside the loop you could also achieve this by: global … Read more

How to make comments work for a post loaded per Ajax?

To quote the Codex on the have_comments function: This function relies upon the global $wp_query object to be set – this is usually the case from within The Loop The problem is that your ajax handler creates its own WP_Query object. Note that you are not calling the_post(), instead you are calling $posti->the_post(). Same logic … Read more

How do you add Read more … link to posts?

Read more links usually appear under following conditions: Template uses the_content() function for display. Post has <–more–> tag in content, which creates teaser. Result is teaser, followed by read more link. Sometimes such links are created artificially by appending them to output of the_excerpt() function in template. So to precisely answer your question – it … Read more

add action only on post publish – not update

Like @milo pointed out in the comment, checking if the post meta exists is the easiest way to achieve what you want – like this: add_action(‘publish_post’, ‘wpse120996_add_custom_field_automatically’); function wpse120996_add_custom_field_automatically($post_id) { global $wpdb; $votes_count = get_post_meta($post_id, ‘votes_count’, true); if( empty( $votes_count ) && ! wp_is_post_revision( $post_id ) ) { update_post_meta($post_id, ‘votes_count’, ‘0’); } } → On … Read more

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