Limit number of pages that use a specific template?

You can approach this by first using a database query to count the number of pages that are already using the template: $query = “SELECT COUNT(*) as total FROM prefix_posts as p JOIN prefix_postmeta as m ON p.ID = m.post_id WHERE p.’post_type’ = ‘page’ AND p.’post_status’ = ‘publish’ AND m.’meta_key’ = ‘_wp_page_template’ AND m.’meta_value’ = … Read more

How to Remove Slug From Database?

I don’t exactly know about the word embed, but by default WordPress reserves & uses these sort of words for internal use. I tried to create a page slug named embed but it wouldn’t work for me either on my localhost or on my live server. Maybe this is reserved for WordPress oEmbed functionality.

Password protected post or page – error message by wrong password?

not really, but can try something like: add_action(‘wp’, ‘check_post_pass’); function check_post_pass(){ if(!is_single() || !post_password_required()) return; global $post; if(isset($_COOKIE[‘wp-postpass_’.COOKIEHASH]) && $_COOKIE[‘wp-postpass_’.COOKIEHASH] !== $post->post_password){ define(‘INVALID_POST_PASS’, true); // tell the browser to remove the cookie so the message doesn’t show up every time setcookie(‘wp-postpass_’.COOKIEHASH, NULL, -1, COOKIEPATH); } } in your template: if(defined(‘INVALID_POST_PASS’)) _e(‘The password you entered is … Read more

Different fields in My Profile page depending on user role

I’ll post whole code which have to be in functions.php it’s legit WP valid code, how it should be done 🙂 This should work, of course you have to put your role name in switch. UPDATED FOR PERFORMANCE: add_action( ‘show_user_profile’, ‘user_fields_for_admin’, 10); add_action( ‘edit_user_profile’, ‘user_fields_for_admin’, 10); function user_fields_for_admin( $user ){ switch ($user->roles[0]) { case ‘SOME … Read more

Set Session Time Limit for Password Protected Posts

The reason is when you execute this code setcookie(‘wp-postpass_’ . COOKIEHASH, ”, 0, COOKIEPATH); It will reset your post password cookie to blank ”, so it just work once To solve this you need to assign the original cookie and extend the timeout, like this setcookie(‘wp-postpass_’ . COOKIEHASH, $_COOKIE[‘wp-postpass_’ . COOKIEHASH], time() + 60 * … Read more

How to get post or page excerpt using post_excerpt

EDIT Seems that I some how misunderstood you. I do think you are missing the point of the post_excerpt. When you create a new post or page (AFAIK for pages as well), you have the opportunity to create a manual excerpt in the excerpt meta box (to make it available, just enable it in screen … Read more

Directing a page to a default subpage

Using WordPress custom nav menus create a menu and add the “General” page 2 times. The first as the parent and the second as the first child then add the rest of the pages as childs under the first General. Change the title in the first general to movies then on the front end when … Read more