How to create new permission for custom post types for doing specific tasks

Check the below code- add_action( ‘admin_init’, ‘the_dramatist_add_role_caps’, 999 ); function the_dramatist_add_role_caps() { // Add the roles you’d like to administer the custom post types $roles = array( ‘editor’, ‘administrator’ ); // Loop through each role and assign capabilities foreach($roles as $the_role) { $role = get_role($the_role); $role->add_cap( ‘read’ ); $role->add_cap( ‘read_{Post_Type_A_Name}’ ); // Also do for … Read more

Loading a stylesheet on a specific page [duplicate]

Try using parent and child class to use css on specific page <div class=”top-container”><span class=”header-text”> content here</span> </div> Assign a page level class .top-container{} And then assign use it as a parent class for styling rest of elements on page .top-container .header-text{} You do not need to load a separate stylesheet rather than you can … Read more

Include images from pages in wp search.php results in default wp search

To include the attachment (media) post type in search results, use the following code snippet function attachment_search( $query ) { if ( $query->is_search ) { $query->set( ‘post_type’, array( ‘post’, ‘attachment’ ) ); $query->set( ‘post_status’, array( ‘publish’, ‘inherit’ ) ); } return $query; } add_filter( ‘pre_get_posts’, ‘attachment_search’ ); Source However, this does not take care of … Read more

Custom Post Type conditional statement for ID of single post

I assume you’re looping through your query the usual way, if so, use the following code if ( $query_parent_products->have_posts() ) : while ( $query_parent_products->have_posts() ) { $query_parent_products->the_post(); // your post specific logic here if ( get_the_ID() == 116 ) { _e (‘my ID is 116’, ‘theme_domain’); } else { the_title(); } } endif;