Instead of using $user_id = get_current_user_id()
, you want to get the ID of the author by doing something like
$author = get_user_by( 'slug', get_query_var( 'author_name' ) );
or
if ( $author= get_query_var( 'author' ) ) { $author = get_user_by( 'id', $author_id ); }
And then use like
$user_id = $author->ID;
Related Posts:
- How to add a .php file to WordPress
- When to use Exceptions vs Error Objects vs just plain false/null
- Woocommerce get selected shipping zone id for the current user
- Include files in functions.php
- Woocommerce -How to set product regular price default
- Display all meta for a post?
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- Add to previous posts under post
- How to show order data by multiple ID?
- Print html when custom field has value inside while loop
- how to create and show sessions in word press?
- Categories Template Assistance
- Stop Duplicating Terms in a Foreach Loop
- Generating add_settings_section() calls dynamically
- How to trash multiple post/product programmatically
- Loading jQuery in the footer after removing jQuery migrate?
- Proper way to edit a post via phpMyAdmin without breaking the compare revisions tool
- Sending jsPDF documents to the server
- Unit Test in WordPress
- “before delete post” action fire when the post is updated?
- Register non hierarchical taxonomy and the show meta box in the post type
- Admin username and password
- Sum custom field values of particular taxonomy
- WordPress excerpt not working
- Random Default Avatar Function
- Custom Text in WooCommerce Order Processing Email Based on Products
- Redirect to another page after submission using wp_mail
- Loop with slider (slider not loading)
- Displaying admin notices inside the block editor from rest_after_insert_{$this->post_type} hook
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- Error when adding excerpt to the content through functions.php
- wordpress media library new uploads don’t write to database
- Fresh Install WP error – “The site is experiencing technical difficulties” [closed]
- Woocommerce : Can’t get product info in loop
- inserting a post from an extern php file but post content doesn’t show on wp site
- Way to add captions to gallery images by code
- Echo possibly causing custom template formatting conflict
- get_template_part for specific page
- proper way to add css using functions.php?
- How do I create my own .php file with a code part and echo it on different pages?
- “Undefined index” error when saving empty array with checkboxes
- Conditional using get_the_ID() not working [closed]
- WordPress plugin admin page – using WordPress function in linked php file
- How to fix this PHP warning in WP-Admin after upgrading to 3.1.2?
- Cant register rest routs from class instance
- if isset not working for undefined index, how to fix
- Decoded malware code [closed]
- PHP Notice: Undefined offset: -1 – Navigation Previous/Next
- Where is the PHP code generating an element?
- How do I check or test a WordPress Auto Year Change Script?
- Trying to enqueue script – Nothing Happens
- Undefined offset: 0-wp-includes/meta.php:488 -Melding
- WordPress and PHP Version Upgrade issue [closed]
- calling function in external js file
- How can I get my Media Uploader Button to function on 1 click rather than requiring 2 clicks?
- Images Uploaded saving onto older/previous year folders
- PHP Redirect condition
- WordPress 4.2.3 on Windows Server 2008 R2 Creating Files as read only
- WooCommerce “Checkout Now” button [closed]
- Woocommerce getting top level category parent and make all sub categories have the same template and menu
- Defining multiple categories for showing latest posts
- Finding and removing duplicates within WP Arrays
- Hard-coding a shortcode as the last menu item in primary navigation?
- Removal of all posts content in bulk, keeping the posts itself
- Blog suddenly shows Archive instead of index page
- Is it possible to access admin-ajax.php using PHP?
- Loading Elementor templates in a Bootstrap modal on button clicking
- Adding custom field to product category and show it to shop/category shop page
- How to check if is page template inside functions.php
- How to hide a div section when user is logged in, in single product woocommerce
- REST API custom endpoint to fetch pages and posts not working
- display custom plugin view on front end inside template body
- Meta inserted through wp_insert_post gets messed up
- If i use a child theme to add new code blocks to header.php, how does it get inserted in the right place in parent’s header.php?
- Wp redirect – reset password
- How do I get data from my database into my Custom Export Field
- Fix hover images blink
- How to auto-generate random numbers in username?
- How to add a custom class for iframe by embed_oembed_html
- Generate random access token to a post page
- Filter loop by ‘price’ with meta_query
- remove public static function wp_link_dialog()
- Find the method which AJAX GET calls
- Adding button to wordpress menu
- List users in a dropdown for login
- WP_Widget dynamic field array with external AJAX
- List of child pages fetch next results at link click
- Limit ads appearing more than three times
- How does add_action ‘comment_post’ work?
- Showing Subcategory’s Name and Link Instead of Parent Category’s
- reorder a WP_Query, using a dropdown
- Programmatically change post templates? [duplicate]
- Select area and checkbox data is not saving?
- Suppress errors when using global function
- In reading settings posts are set to “blog” and I have page-blog.php but no posts
- using a shortcode in a hyperlink
- Woocommerce – add tracking code to another email template
- How to add custom user role into wordpress
- change title of page dynamically
- Custom Filtering date with newsletter