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

Display posts by month

As said in a comment, you can do this in one query. The principle here is to only display the date heading if the post date’s month of the previous post does not match that of the previous post FEW NOTES Before I start, a few notes: Never use query_posts, except if you really need … 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

post__in for get_posts with a dynamic array

Here’s one way by using wpdb::get_col() and fetch the id column: $pids = $wpdb->get_col( “SELECT id FROM my_table” ); We could then clean it by integer convert each id with: $pids = wp_parse_id_list( $pids ); Just note the different max value for intval(), depending on 32 or 64 bits systems.

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