Difference between an archive and a page listing posts

Archive Page An archive page is part of the WordPress Template Hierarchy, and is the template file WordPress uses to display the archive index list for a given post type. The custom post type archive template hierarchy is as follows: archive-{posttype}.php archive.php index.php WordPress uses the query parameters to output this page, and posts are … Read more

simply loop through posts

Because you’re on a page, that’s only going to display the query for that page. As such, you’d have to create a new query to bring in the posts you want. Replace your loop with this: <?php $args = array( ‘post_type’ => ‘post’ ); $post_query = new WP_Query($args); if($post_query->have_posts() ) { while($post_query->have_posts() ) { $post_query->the_post(); … Read more

Changing the post date and time with function

Call wp_update_post() with a special value for ‘post_date’ and ‘post_date_gmt’: $time = current_time(‘mysql’); wp_update_post( array ( ‘ID’ => 123, // ID of the post to update ‘post_date’ => $time, ‘post_date_gmt’ => get_gmt_from_date( $time ) ) );

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)