Show current user posts only

<?php $query = new WP_Query([ ‘author’ => get_current_user_id(), ]); while ( $query->have_posts() ) { $query->the_post(); the_title(); } wp_reset_postdata(); ?> In the example above we are using WP_Query look on the reference guide for additional parameters such as different post types like if you want to get only pages, posts or custom post types, as well … Read more

user_meta table in staging vs live site

Passwords are stored in users not usermeta. I’d copy both tables over and it’ll work fine. `wp_users` ( `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `user_login` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ”, `user_pass` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ”, `user_nicename` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ”, `user_email` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT … Read more

Showing User’s Post Counts by Custom Post Type in the Author.php?

Here I’ve modified the code from URL you’ve given. function _yoursite_get_author_post_type_counts() { static $counts; if (!isset($counts)) { global $wpdb; global $wp_post_types; $sql = <<<SQL SELECT post_type, post_author, COUNT(*) AS post_count FROM {$wpdb->posts} WHERE 1=1 AND post_type NOT IN (‘revision’,’nav_menu_item’) AND post_status IN (‘publish’,’pending’, ‘draft’) GROUP BY post_type, post_author SQL; $posts = $wpdb->get_results($sql); foreach($posts as $post) … Read more

Querying specific table row by current user login

Welcome! WordPress already have a table for users. Also, there is another table named usermeta that will allow you to save extra information for users. There are some functions that allow developers to get information from user and usermeta tables without using custom database queries. add_user_meta update_user_meta delete_user_meta get_user_meta Solution: As mentioned in the question, … Read more

Web app vs CMS backend

The idea of birgire is interesting but this can already be done with a single post per user. Create users with the role “Contributor” and then each user create a post with this content button 1 text a sentence, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor … Read more

Why get_user_by() doesn’t work in my code?

I tweaked your code to make sure the $email was defined before attempting to process. I stop where the problem may be. If you follow all the if and else code, the “continue”resident when an email address is NOT a part of a particular group (subscriber, admin, customer etc) will skip the processing and move … Read more

Check if current user has a post and that post has any term/s from a specific custom taxonomy outside the loop

This can be done using WP_Query using author and tax_query. Something like this: $args = array( ‘post_type’ => ‘post’, ‘author’ => get_current_user_id(), ‘tax_query’ => array( array( ‘taxonomy’ => ‘custom-taxonomy’, ‘operator’ => ‘EXISTS’ ), ), ); $query = new WP_Query( $args ); And then check if posts are returned through this query. Please note that this … Read more

What’s the correct way to add capabilites to user roles?

The best place to add this would be in the plugin’s activation hook. You can either call the dynamic activate_{$plugin} hook, or better yet use the provided register_activation_hook method. Using your code example above – something like this would be what you’re looking for: register_activation_hook( __FILE__, function() { $role = get_role( ‘editor’ ); $role->add_cap( ‘edit_booked_appointments’, … Read more

How to set all external links from a certain user to “nofollow”?

You want to try something like this (untested): // Nofollow in content $author_id = get_the_author_meta( ‘ID’ ); add_filter(‘the_content’, ‘my_nofollow’); function my_nofollow($content) { //return stripslashes(wp_rel_nofollow($content)); return preg_replace_callback(‘/<a[^>]+/’, ‘my_nofollow_callback’, $content); } function my_nofollow_callback($matches, $author_id) { $link = $matches[0]; $site_link = get_bloginfo(‘url’); if ($author_id === 4) { if (strpos($link, ‘rel’) === false) { $link = preg_replace(“%(href=\S(?!$site_link))%i”, ‘rel=”nofollow” $1’, … Read more