The problem with your code lies in these three lines:
$queried_post = get_post($post_id);
$author_id = $queried_post->post_author;
$first = $user_info->user_nicename;
You correctly get authors ID, but then you try to get some field of user_info
variable, which is not defined anywhere in your code.
One way to fix it is to get user info (using get_userdata
) before trying to access it:
$author_id = $queried_post->post_author;
$user_info = get_userdata( $author_id );
$first = $user_info->user_nicename;
You can also use get_the_author_meta
to obtain only the field you need:
$author_id = $queried_post->post_author;
$first = get_the_author_meta( 'user_nicename', $author_id );
Related Posts:
- What is This esc_html_e() i wordpress php?
- Build a content and excerpt grid loop with paging and options for # of posts
- Displaying post per day
- How to add active class to custom menu using while loop and wp_list_pages
- delete an array element when its date expires
- How can I loop into two different DIVS without repeating the DIVs
- How to speed up a wordpress function with multiple loops?
- Custom excerpt function re-factoring
- Get first URL from post content
- Show css depending on activity type in BuddyPress activity-loop [closed]
- Blog posts repeat
- how to refresh div on template part?
- Can’t find infinite loop cause
- Checking array against author id in loop
- Custom Pagination is Broken
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- use loop to return blog details
- How to get current post category details inside “loop”?
- Calling function in loop causes repeat data
- Strip from or something better?
- How to Add a cutsom slug to my custom author role
- Products listing check if meta checkbox is checked
- How to output the taxonomies that are assigned to each custom post?
- update_user_meta as multiple value but with same meta key
- cURL needing to loop through all “next_page”
- WordPress Ajax filter: Create two loops for different output styles?
- How can I get my pagination loop to display the correct number of total pages?
- How to sort (orderby) a query done by a template function before the ‘foreach’ loop?
- How fix error in the WordPress loop?
- My query keeps looping infinitely ! how to stop it?
- Retrieving specific images from Media Library
- Modify category archive page loop on functions.php
- Pagenav Not appearing on custom Template
- Options.php loop won’t show!
- Loop on a wordpress Page instead of content coming from the WP text editor
- start_lvl Ignored in Custom walker_nav_menu
- Enforcing password complexity
- How do I make my function add variables/values to the $post object?
- Check if a menu is empty?
- Calculate percentage of post by category
- Dynamically change feature image in customiser
- Change comments form title on a page by page basis
- Creating wordpress user registration form
- Get the title before comma
- category not display in word press grammatically
- Getting a fatal error while updating
- “Can’t use function return value in write context” error
- Display 4 chronological posts starting with a random post
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Displaying Only Certain Tags in Loop
- my function doesn’t return my post from today
- Warning: array_pop() expects parameter 1 to be array, boolean given
- Way to display “Yesterday”, “Today”
- get_the_terms – only top level
- Have CSS Class Added with `is_page()` WP function
- Slide in Panel WordPress Post
- Use wp_get_recent_posts with search term
- Run a filter when a walker runs
- have_posts() execution failure
- comments_number display outside specified span
- Display fields as values in array from external SQL DB
- Passing the custom field values in the wp_get_current_user array function
- Populate dropdown with Child Pages based on Parent Page chosen
- How can I remove a function that has been added to wordpress with add_filter?
- Get value from shortcode to do something
- PHP 8, AJAX mail form to function.php doesn’t work
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- Display category name only once inside loop
- How to display login form anywhere, when user isn’t logged in, without redirecting?
- Widget back end radio button issue
- GET problem in WordPress
- Help with WordPress function inside a shortcode
- Send a mail to specific address in a custom field when a new comment is made on a specific post
- WP All Import / Update stock quantity from multiple XML files
- How to style injected code in header section?
- Hide a div when a custom field is empty
- Echo array value
- How to break up php code to avoid echo
- SQL error with custom query
- How to change basename url for wp-admin?
- How to exclude meta no index pages from wp_list_pages
- require get_template_directory() . ‘path/to-my/file.php’ BREAKS customize > themes functionality
- Edit a function to take different actions based on user role
- How to put 2 php codes in functions.php without site crashing
- Unzip_file causing Media file upload error
- How do if all posts has this category ID then do this
- View tag description on page
- WP HTTP API call response
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Escaping a Single Quote in str_replace for Nav Function
- Private messaging – Getting and displaying the avatar/url of a message recipient
- Display product attributes for current product
- How to have post count after each listed category
- How can I put a custom field as the link of a button shortcode?
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- Fix My Custom Function: Remove Automatic
- WP Debug enabled Undefined index error in a widget
- is there away to hide php code in wordpress not to show in PAGES
- Automatically change insurance quantity based on cart total [closed]
- How to pass value to add_filter wpcf7_form_tag from another function?