Adding a blog archive with pagination using WP_Query

You can calculate offset via paged and posts_per_page. E.g: $per_page = 6; $paged = get_query_var(‘paged’) ? : 1; $offset = (1 === $paged) ? 0 : (($paged – 1) * $per_page) + (($paged – 1) * 2); $args = array( ‘order’ => ‘ASC’, ‘paged’ => $paged, ‘offset’ => $offset, ‘orderby’ => ‘ID’, ‘post_type’ => ‘post’, … Read more

What do comments with […] mean?

Its most likely to be a TrackBack or pingback: In a nutshell, TrackBack was designed to provide a method of notification between websites: it is a method of person A saying to person B, “This is something you may be interested in.” To do that, person A sends a TrackBack ping to person B.

Shortcode to display the latest news article within a page

In functions.php file : function my_recent_post() { global $post; $html = “”; $my_query = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 1 )); if( $my_query->have_posts() ) : while( $my_query->have_posts() ) : $my_query->the_post(); $html .= “<h2>” . get_the_title() . “</h2>”; $html .= “<p>” . get_the_excerpt() . “</p>”; $html .= “<a href=\”” . get_permalink() . “\” … Read more

Query Posts by Custom Field

You can achive this using WP Query with meta_query argument as following. $args = array ( ‘post_type’ => array( ‘post’ ), // YOUR POST TYPE ‘meta_query’ => array( array( ‘key’ => ‘country’, ‘value’ => $your_country, // THE COUNTRY TO SEARCH ‘compare’ => ‘LIKE’, // TO SEARCH THIS COUNTRY IN YOUR COMMA SEPERATED STRING ‘type’ => … Read more

Why does WP_Post not contain its permalink?

WP_Post is a representation of the post as it exists in the database, and the permalink isn’t stored in the database. It’s not stored in the database because it’s not a property of the post. The permalink is determined by the site’s address, its permalink structure, and the post’s slug. Imagine if updating the permalink … Read more