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

Need help targeting a custom post type with conditional tags

You want the first parameter ($post_type) of register_post_type() – by default this is used for the “slug“, so in your case it’s: content-block The name and singular-name labels you refer to are just for display purposes – see get_post_type_object() for an example. So this should work (note I’ve not tested the rest of your advert … 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

Creating bulk posts with Youtube videos

You already have your updateYoutube() function. Edit it to insert a new post. Very generally: function updateYoutube( $videocode ){ global $conn; $run = $conn->query(“SELECT `ID` FROM `youtubetable` WHERE `ID` = ‘$videocode'”); if ($run->num_rows > 0) return false; else { if ($conn->query(“INSERT INTO youtubetable (`ID`) VALUES (‘$videocode’)”) === TRUE) { // ################################# // NOTE: The following … 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)