Get user in rest API endpoint

Thanks to Jacob Peattie, I was able to solve this issue. You have to include a nonce from the WordPress Javascript API in your REST API requests if you wish to use information about the current user. From the WordPress documentation: If no nonce is provided the API will set the current user to 0, … Read more

Page template not working when logged out

I found the solutions: I created a duplicate header and footer file named them header-nonavigation.php and footer-none.php In these files, I deleted the navigation code and the footer code (do not hide the navigation/footer for some reason it won’t load the correct php header/footer files) I called to these files in my page template php … Read more

Get all of a user’s posts (custom post type) then get cumulative value of a specific meta_key value from those posts

add_shortcode( ‘show_total_listing_price’, ‘show_total_listing_price’ ); function show_total_listing_price ( $atts ) { global $post; $args = array( ‘author’ => get_current_user_id(), ‘post_type’ => ‘POST_TYPE_GOES_HERE’, ‘posts_per_page’ => -1, ‘post_status’ => ‘publish’, ); $query = new WP_Query( $args ); $total = 0; if( $query->have_posts() ){ while( $query->have_posts() ){ $query->the_post(); $price = get_post_meta( $post->ID, ‘PLACE_META_KEY_HERE’, true ); $total += $price; } … Read more

Comment restrictions Wodpress

The comments_open() boolean function return is filtered by ‘comments_open’. Untested, pseudo code as a guide: add_filter( ‘comments_open’, function( $open ) { $user = wp_get_current_user(); $open = $open && $user && time() – mysql2date( ‘U’, $user->user_registered ) > 3 * DAY_IN_SECONDS; return $open; } ); No guest users will be able to comment either, and I … Read more

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