Modify previous and next post links to current Authors Other posts

The correct method of doing this since WordPress 4.4 is simply the following: add_filter( “get_next_post_where”, function($where, $in_same_term, $excluded_terms, $taxonomy, $post){ $where .= ” AND p.post_author=””.$post->post_author.”””; return $where; }, 10, 5); add_filter( “get_previous_post_where”, function($where, $in_same_term, $excluded_terms, $taxonomy, $post){ $where .= ” AND p.post_author=””.$post->post_author.”””; return $where; }, 10, 5); Note: Please do not follow levidia1221’s accepted response, … Read more

How Do I Get My Post Tags to Alphabetize?

You could use the filter term_links-post_tag to sort tags while ignoring their case: add_filter( “term_links-post_tag”, ‘themeslug_sort_tags_alphabetically’ ); function themeslug_sort_tags_alphabetically( $tags ){ natcasesort( $tags ); return $tags; } This code is to be placed in the functions.php of the child theme.

How to change “post_class()” for a custom post type?

As documented here: https://codex.wordpress.org/Function_Reference/post_class#Add_Classes_By_Filters You can add a hook to the ‘post_class’ filter to add/remove classes in the array passed. You can use the various template tags like has_post_format() and others to see what classes you need to add; you’ll have access to the ID of the post in question. You could erase the array … Read more

Exclude current custom post on single post

Refer to the WP_Query Codex page for a full list and explanation of parameters. The one you want in this case is post__not_in. $recent = new WP_Query( array( ‘post_type’ => ‘works’ ‘posts_per_page’ => 5, ‘post__not_in’ => array( $currentID ) ) );

How do I retrieve a users’ last 5 posts?

Basically, when you want get posts, you should think about WP_Query. It’s already in the docs for your question. You can get posts by an author like this $query = new WP_Query( array( ‘author’ => AUTHOR_ID, ‘posts_per_page’ => 5 ) ); You can even get posts by more than one author, like this $query = … Read more

How to get a post’s content? [closed]

“best” greatly depends on context. guid is probably (with some debate about it) the best way to uniquely identify a post, but not all import/export plugins leave it alone without changes. ID is a good identifier if you do not care about import and export. Slug is problematic because they might be changed by the … Read more

How to get posts from a current post’s month?

There is date_query which can handle this and an SQL query is not a good practice when you can take advantage of WordPress Query API: $pid = 1; // post ID here $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’, ‘date_query’ => array( array( ‘year’ => get_the_date(‘Y’, $pid), ‘month’ => get_the_date(‘m’, $pid) ), ), … Read more

pagination on data fetched using SQL query

<?php global $wpdb; // QUERY HERE TO COUNT TOTAL RECORDS FOR PAGINATION $total = $wpdb->get_var(“SELECT COUNT(*) FROM (SELECT * FROM muslim LIMIT 0,431) AS a”); $post_per_page = 10; $page = isset( $_GET[‘cpage’] ) ? abs( (int) $_GET[‘cpage’] ) : 1; $offset = ( $page * $post_per_page ) – $post_per_page; // QUERY HERE TO GET OUR … Read more