[Resolved] Single Post Author Template to show data from ACF on Author Profiles

Home Forums Support [Resolved] Single Post Author Template to show data from ACF on Author Profiles

Home Forums Support Single Post Author Template to show data from ACF on Author Profiles

Viewing 15 posts - 1 through 15 (of 28 total)
  • Author
    Posts
  • #2506920
    Saul

    I am looking to display some data from WordPress Users Profiles on Single Author Pages dynamically. I have already added the necessary fields and data using ACF, as seen in the screenshot provided (https://prnt.sc/Z4JUwvrKj3ZO). The goal is to show the data added for each individual Author/User on their respective profiles (ex: domain.com/author/author1, domain.com/author/author2, etc.). I have also created a Content Template Block where I am retrieving all data from the Author meta using GP’s Dynamic Data Feature (https://prnt.sc/c2mqwqB95BdS). However, there is currently no option in the Display rules to set the Template for for Single Author Pages.

    Someone already asked this question (https://generatepress.com/forums/topic/single-post-author-template/) in the forum but there is no clear answer.

    #2507101
    David
    Staff
    Customer Support

    Hi there,

    there is no single author.php template in GeneratePress.
    the theme uses the archive.php practically anywhere there is an archive ( aside from index.php ).
    So you would use the Author Archive display rule for that.

    If you use a Block Element – Loop template, this removes the default theme loop.
    So you can use that element type, and populate it with dynamic data to make it your own

    #2508179
    Saul

    Thanks David! So… I turned my template to Block – Loop template from Block – Content Template which it was earlier. And, I set the template to display on “Author Archives” for “All Users” but there are two issues:
    1. It’s not working for all users. It’s just working for one user and for the rest of the users it’s fetching no data.
    2. Somehow the image added though the custom fields are not showing.

    Here is a video showing all setup: https://share.vidyard.com/watch/VBNSKzNyvcJctLSPhZCJAF?

    #2508199
    Fernando
    Customer Support

    Hi Saul,

    Yes, can you share admin credentials so we can take a closer look?

    Please use the Private Information field again for this.

    #2508308
    Saul

    Sent it!

    #2508363
    David
    Staff
    Customer Support

    Are there any posts published ( not draft ) for those users who are missing their data ?

    #2508379
    Saul

    Ah! I see. Other authors who I tested haven’t posted any post. And, if I assign any post(s) to an author without any post(s) then the profile shows data added though the custom fields. How, I can remove that check so that any author even without 0 posts shows the custom fields data. Also, the Profile Pic (the image) added through custom field is not showing on Author Profile.

    #2508426
    David
    Staff
    Customer Support

    Yeah, thats tough, aside from creating a custom PHP template i am not sure on this. The issue arises is that the $authordata is only gathered in the loop. And as there are no posts to loop through there is no loop and therefore no dynamic data.

    What is the endgame here? Will all author have their own posts ?

    #2508544
    Saul

    Makes Sense! As such all Authors will have the posts so we are good. I just wanted to see if it’s possible to remove that check. But, I can understand what you said so let’s leave it. Can you please look into the Image thing and let me know how to fix that? The image added though Custom Field is not showing on the Author Profile.

    #2508555
    David
    Staff
    Customer Support

    As any CF saved to the user would need to come from the Content Source: Author Meta.
    And i don’t think the GB Image block supports that. If it doesn’t then we would need to create a shortcode or use a render_block filter. Let me know.

    #2508688
    Saul

    I double checked and Content Source: Author Meta is not available for the image.

    #2509184
    Saul

    So how to approach this? If we add a shortcode with CF value for the image in place of the image will it show image added on each profiles dynamically?

    On a separate thing… I am trying to create a Post Meta Section inline to this reference https://prnt.sc/K0q7lVS-Q8_p where I need to display Post Author and Medically reviewed by Author (Fact checked by author in my case). The fact checked by author will be a person from WordPress users list. To accomplish this I have already created a custom field, type “User” https://prnt.sc/s1HiUsHiUr77 which shows a dropdown (https://prnt.sc/nx_eUkeCh8p0) though which I can set any WP User as the Second Author/Fact Checker. I have used Post Meta Template to render this inside WP Posts. However, there are two issues:
    1. The template is not Fact Checked by Author field value: https://prnt.sc/hl40O-XmvC5c and instead it’s showing the Author Name it’s showing Author ID.
    2. I want the Post Meta to appear after Post’s H1 tag but there is no hook to render it after H1 tag.

    Please refer to this screenshot: https://prnt.sc/gngqdj-Pk921 (Test Post URL is sent privately).

    #2509199
    David
    Staff
    Customer Support

    Yeah, will need a shortcode to show the image.
    Which is a bit more tricky then a straightforward field on a single post.
    Not 100% sure on this, but give this a try for creating a shortcode for the user image:

    add_shortcode('show_user_image', function(){
        $html = '';
        $image = get_field('your_field_name', 'user_'. get_queried_object_id());
        if ( $image ) {
            $html = '<img src="' . $image .'" width="150" height="150" />';
        }
        return $html;
    });

    You need to change the your_field_name to the actual field name,
    Then just add the [show_user_image] to your template.

    Give that a shot.

    Regarding the other questions:

    1. What is the Custom Field set to return in the ACF settings ?
    2. How is that post template constructed ? The HTML is not the default GP Theme single post template?

    #2509383
    Saul

    Thanks David! But no luck with that shortcode. It’s simply showing the image path: https://prnt.sc/-qv7mZh_0PPR for the user I am logged in with and for another user who has the posts it’s not showing anything: https://prnt.sc/4uBtyVwErlIF URLs for both profiles are sent privately.

    Regarding your questions:
    1. The custom field type is user: https://prnt.sc/EMhhCU4at87e which shows a dropdown (https://prnt.sc/nx_eUkeCh8p0) on all posts though which I can set any WP User as the Second Author/Fact Checker and trying to render the data on front-end using dynamic options: https://prnt.sc/hl40O-XmvC5c
    2. The Post Template using WordPress’s default template. All posts in WP were actually HTML Pages in our old website which we migrated to WP using a custom PHP script.

    #2509385
    Saul

    URLs in the Private information field

Viewing 15 posts - 1 through 15 (of 28 total)
  • You must be logged in to reply to this topic.