Dynamically generate child-URLs for posts or custom posts

I just completed something like this (with great help from folks on this site). First, you need to add the rewrite endpoint to your functions: function wpa_read_endpoint(){ add_rewrite_endpoint( ‘sub-url’, EP_PERMALINK); } add_action( ‘init’, ‘wpa_read_endpoint’ ); Make sure to then go to the permalinks section of admin and save to refresh permalink settings. Then add some … Read more

Show total author’s post views by posts post_meta

It’s showing you the first 5 posts because that’s how many posts are on page 1, and you never told it how many posts per page to load, so it used the default posts per page you set under settings. You’ll want to modify the get_posts call to have the posts_per_page parameter. However, I will … Read more

Count search results in heading

If you check the documentation for WP_Query you will notice that post_count, which you are using, returns the number of posts being displayed. That is what you see, but not what you want. found_posts returns the total number of results for the query, which is what you want. $post_count The number of posts being displayed. … Read more

Mark menu item as current-menu-item for category

I use this functions. First of all, you have to add some custom class to your menu item (allow class input in Screen options, it’s not visible by default). function mark_menu_item_as_active($classes, $item) { if( in_array(‘my-custom-class’,$classes) && ( is_category(‘my-category’) /* OR …*/ ) ) { $classes[] = ‘current-menu-item’; } return $classes; } add_filter(‘nav_menu_css_class’, ‘mark_menu_item_as_active’, 10, 2); … Read more

How to rename “Publish” metabox title in post screen

The best way would be to remove the meta box and then add it back in with your new title: function change_publish_meta_box() { remove_meta_box( ‘submitdiv’, ‘post’, ‘side’ ); add_meta_box( ‘submitdiv’, ‘YOUR TITLE HERE’, ‘post_submit_meta_box’, null, ‘side’, ‘high’ ); } add_action( ‘add_meta_boxes_post’, ‘change_publish_meta_box’ ); (Change YOUR TITLE HERE to whatever you want)

Buddypress activity id

That function is called right in entry.php as follows: <li class=”<?php bp_activity_css_class(); ?>” id=”activity-<?php bp_activity_id(); ?>”> Note that bp_activity_id() will echo the value. To use the value in code, call bp_get_activity_id().

Automatic post deletion

You can improve by storing the “expiry” time of post as a meta instead of the publish time. This way you can query for posts with meta which is smaller then the current time and draft them, no need to loop over all posts. Drawback is that you will have to decide how to handle … Read more

How to access featured image?

get_the_post_thumbnail ( $post/$post_id, $sizes, $attr ) will give you the featured image as html to output. get_post_thumbnail_id ( get_the_ID ( ) ) will give you the ID of the featured image so you can use it to get more information. Getting the thumbnail ID is essentially accessing the the post’s meta data: $image_id = get_post_meta( … Read more