Attach pdf file to custom post type

Here this is my code which i used in my wordpress site in custom post type for adding the pdf to the post and its work for me try to change its and use it. Hope it will help function add_custom_meta_boxes() { add_meta_box(‘wp_custom_attachment’, ‘Hotel Brochure’, ‘wp_custom_attachment’, ‘hotel_post’, ‘normal’, ‘high’); } add_action(‘add_meta_boxes’, ‘add_custom_meta_boxes’); function wp_custom_attachment() { … Read more

Delete posts from a post type automatically via Cron

Although I do not understand the motivation for truncating posts, I think this exercise is valuable for you to understand how to use cron + WordPress. Create a function to truncate posts This can be used for both methods below WP-cron or UNIX cron. function foobar_truncate_posts(){ global $wpdb; # Set your threshold of max posts … Read more

Display content from a specific category

The argument isn’t category, it is cat. Your query fails because you are using an argument that doesn’t exist. $args = array( ‘post_type’ => ‘post’ , ‘orderby’ => ‘date’ , ‘order’ => ‘DESC’ , ‘posts_per_page’ => 6, ‘cat’ => ‘3’, ‘paged’ => get_query_var(‘paged’), ‘post_parent’ => $parent ); $q = new WP_Query($args); if ( $q->have_posts() ) … Read more

Counting words in a post

How hard did you search? I searched Google for “wordpress count words in post” and found a function for it in the first result! Put this in functions.php: function prefix_wcount(){ ob_start(); the_content(); $content = ob_get_clean(); return sizeof(explode(” “, $content)); } Then call it in the template like this: <?php echo prefix_wcount(); ?>

Check if post has children or not

You can first attempt and get a list of post’s children. If the returned value was empty, then the post has no child. Here’s how you do it: $args = array( ‘post_parent’ => get_the_ID(), // Current post’s ID ); $children = get_children( $args ); // Check if the post has any child if ( ! … Read more

Most efficient way to insert a post outside WordPress?

If you’re on a remote server, XMLRPC would be best, but requires login details If you’re in a PHP script on the same server, wp-load.php would be best ( XMLRPC will involve a request of sorts ) If you’re in a bash or CLI script, WP CLI would be best, e.g.: wp post create –post_type=page … Read more

Add role that restricts user to post in specific category

You can use the get_terms hook to find all categories and restrict access to them by ID or slug, if the current user is not an admin, or in this specific case if the user doesn’t have the role assigned by you. add_filter(‘get_terms’, ‘restrict_categories’); function restrict_categories($categories) { $onPostPage = (strpos($_SERVER[‘PHP_SELF’], ‘post.php’) || strpos($_SERVER[‘PHP_SELF’], ‘post-new.php’)); // … Read more

How to disable Uncategorized category URL?

First you need to go in Setting >> Writing. Then, you need to follow below steps. Step 1: Change Your Default Post Category Step 2: Delete Uncategorized It may chance that you may have some posts in Uncategorized category. You just need to transfer those posts to new default category. So, don’t worry your problem … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)