Skip Navigation

[Resolved] show user (author) profile with published posts

This support ticket is created 5 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 34 replies, has 4 voices.

Last updated by Nigel 5 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#1219658

Hello

This is an ad site for amall agricultural producers, they publish ads about their products. I have a custom role for them. I want to list every producer > click on their name > have an author page with basic info and list of ads.

I tried first creating an author archive but I simply can't create it, loader is spinning, nothing happens.

Second approach was a page with a view of all authors with a given role. This is the content template part of the loop.

<a href="../author/[wpv-user field='user_nicename']">[wpv-user field="user_lastname"] [wpv-user field="user_firstname"]</a>

This lists the authors (producers) and I have a link but I don't have a single page for authors. Divi has no author.php and index.php was not overtaking it. So I created author.php:

<?php get_header(); ?>

<div id="main-content">
<?php echo do_shortcode('[et_pb_section global_module="508"][/et_pb_section]');?>
</div> <!-- #main-content -->

<?php get_footer(); ?>

This displays a Divi library item in which I can add the toolset shortcodes. Much like when creating a content template the harder way... Of course I created a view that should display the ads of the producer. But my problem is how to pass what posts the view should show? How to add the author id? And I need to show the author info in the template the same way only for the author that is currently displayed.

#1220068
Screen Shot 2019-03-24 at 2.57.44 PM.png

I tried first creating an author archive but I simply can't create it, loader is spinning, nothing happens.
I see an error in the browser console here. It's HTTP 403, strictly forbidden. I'm not sure why this URL would be forbidden, but I often see strange issues on LiteSpeed environments. If you can clear the cache from wp-admin it might help. Also you may be able to get more information about these specific errors from your host.

You could try the following troubleshooting steps:
- Update WordPress, Divi and all plugins to use the latest versions.
- Temporarily deactivate all plugins except Types and Views, and switch to the default Twenty Nineteen theme.
- Test again. If the problem was resolved, reactivate your theme and other plugin one by one until the problem returns. Try to pin down a specific combination responsible for the problem.

But my problem is how to pass what posts the view should show? How to add the author id?
You can configure the author filter to respond to a shortcode attribute "authors". Then you need a shortcode to determine the author's ID from inside the author WordPress Archive. I have a snippet available you can use. Add this to your child theme's functions.php file, or create a new snippet in Toolset > Settings > Custom code.:

function get_author_id_in_archive_func($atts) {
  return get_the_author_meta('ID');
}
add_shortcode("get_author_id_in_archive", "get_author_id_in_archive_func");

Here's how you would use it with your post author Query Filter:

    [wpv-view name="your-view-slug" view_display="layout" authors="[et_author_id_in_archive]"]
   [wpv-view name="your-view-slug"  ]
#1220302

It was not working, unfrotunately there is a bug somewhere in Divi or Toolset. When using shortcodes within shortcodes in a Divi library item the second shortcode is not interpreted, and I get a this at the end of the output: ]"

But I don't have time now for bugs so I tried another approach. I created a page for the user profile (hidden link), and I passed this argument from the user list loop template to this page (actually this is a much simpler approach I guess):

<a href="../producator/?author-filter=[wpv-user field='ID']">[wpv-user field="user_lastname"] [wpv-user field="user_firstname"]</a>

And I set up a view filter to Select posts with the author's id determined by the URL parameter "author-filter". And this should work without problem but it is not. It shows all published posts from every user. The user meta I show before the view is working fine with this URL parameter: hidden link

Please help me find what the problem can be.

#1220341

And another quite strange thing that pagination is not working on this page: hidden link.
And it is not working on this either: hidden link

Pagination is working on other views on the site.

Maybe it is related...

#1220510

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Joszef,

Christian is out today but should return tomorrow to continue assisting.

Thanks,
Shane

#1221418

Please assign me somebody who is closer to my time zone (GMT+2) and is available. I really need to solve this problem very urgently... Thank you.

#1221746

Hi, I have reassigned your ticket to Nigel, who is closer to your timezone. He will follow up with you soon.

#1221797

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2019-03-27 at 15.41.06.png

Hi Joszef

I also tried to create a custom author archive and saw a 403 error for the admin-ajax request.

You really should contact the host to try and identify why this is happening, because it is forcing you to try and workaround the inability to use an author archive and might also explain why you are having other unexplained issues.

Where Christian proposed you use a custom shortcode to provide the value for an authors attribute I noticed a typo in the name of the shortcode he provided for that attribute, and if you did not notice that yourself and correct it then this second shortcode would not have been parsed because it was not, in fact, a registered shortcode.

If you registered a shortcode get_author_id_in_archive with Christian's code then you would insert the View in a Divi module like so:

{!{wpv-view name="your-view-slug" view_display="layout" authors="[get_author_id_in_archive]"}!}

Note that Toolset shortcodes should be inserted in Divi modules using the custom {!{shortcode}!} format rather than square brackets.

I can't verify what you registered the shortcode as, I was expecting to find the code for that at Toolset > Settings > Custom Code, but you have added it elsewhere.

I checked the pagination issues.

On this page it seems to work fine: hidden link

But on this page it does not work and there is a JS error in the console (screenshot): hidden link

Can you disable all non-Toolset plugins and switch to the parent Divi theme and re-test to see if that affects the pagination? If the error disappears then it should be possible to determine the source of any conflict through a process of elimination.

#1221884

Hello Nigel!

Please read my reply #1220302. Christian's solution was not working unfortunately because there is a bug somewhere in Divi or Toolset. I cannot use shortcode inside a shortcode if in a library item. Of course I corrected the typo and registered the shortcode. I always use child theme and functions.php. I cannot upgrade to the last plugin versions, if I remember correctly you told me in another ticket to wait for the new version of Forms. Maybe the author archive problem is just because a plugin verison problem, I can create other types of archives. Of course I will clear the server problem with my hosting but I really don't have time to wait after them. So I tried to approach this author list and author page the simplest way possible.

I pass the author's id from the author list to: hidden link to show all the ads by that producer. I passed it to the view by URL and I need that ID for the author meta info too, that part is working well, but the view simply shows every post ever posted in the CPT by every author. And I'm quite sure that I set up the view correctly. I even recreated it several times to be sure. I tried to get the author by URL or by shortcode attribute too (for this I also used the URL param as shortcode in the view).

The pagination now works by creating a totally new view and using a very simple loop content, I hope it will work when I create a more complex layout to list that view. I've seen that there is javascript error in the console but I have no idea how that appeared.

But the biggest problem now is that I have to show all the ads of the author in who's page the visitor arrives. And I don't understand why the view is not working because it is a fairly simple scenario.

#1222279

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I cannot use shortcode inside a shortcode if in a library item.

By library item do you mean a global module?

If that's the case then this is a known issue, we have been trying to get some response from Divi for months for a small update that would fix the problem of shortcodes-within-shortcodes in Divi global modules.

If you use a normal module instead of the global module then that should work correctly, you'll have that solution available to you. Could you check?

#1222301

No, it is not a global module, it is a layout. And I inserted the layout in a php with do_shortcode. I know in the code appears global_module but in the library it is a normal layout. I used this approach several times, I found it in a tutorial about how to create archives with divi. And talking about bugs, you mentioned I should use the curly brackets shortcodes in divi. Those sometimes don't work there are cases when only the square brackets work. But don't ask me exactly when, I found out this more than a year ago and from that on I use only square brackets.

But let's leave this behind, my last approach I was writing about is much simpler. Please help me understand what is the problem with my view?

#1222383

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2019-03-28 at 12.14.35.png

On your site you have one post authored by user id=8, so I tested the page, specifying that author like so:

hidden link

The wrong results are displayed (i.e. all the posts).

I turned on the Views debug mode (in Toolset > Settings > Front-end Content) and revisited the page.

You can see the debug results in the screenshot.

According to the View arguments that are used to generate the WP_Query, the author should be author = 8, which is as expected.

But look at the resulting MySQL query that WP_Query actually generates. It adds an author condition that author != 15, which is an entirely different condition than the one passed from Views.

So something else is hijacking the query and replacing the author query.

I disabled non-Toolset plugins to see if I could determine what, but that made no difference.

So I switched theme to the parent Divi theme, and now it works as expected.

So it seems like custom code you have in your child theme is responsible for the problem.

(I've left it in that state so you can see it working.)

#1222412

That's quite strange. Would you look at my code, could I send you somehow my functions.php? I can't find which function adds this strange author condition in the query...

But in the meantime I solved with my hosting company the author archive problem. There was a php security mod that caused it, and they deactivated that for this account. So Author archive is working now and the query there seems correct. I created a page for the author list and it links every author to the archive: hidden link. Would you look at this too please? My only problem with this now is that I added the content template that pulls the author's meta infos before the loop, but when the author has no posts it doesn't display the meta either.

#1222530

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I can download your child theme to look at the functions.php, and I'll check the other details, but it will be in the morning, I'm closing now.

#1222979

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

This is presumably the code responsible:

function remove_unvetted_authors( $query ) {
    if ( !is_admin() && $query->is_archive() && !is_page( 31 ) ) {
        $user_ids = get_users( [
            'role'   => 'producator_neautorizat',
            'fields' => 'ID'
        ] );
 
        $query->set( 'author__not_in', $user_ids );
    }
}
add_action( 'pre_get_posts', 'remove_unvetted_authors' );

I couldn't see where you are adding the author meta, it's directly in the PHP template?

See the Custom Author Information section of this article in the codex for details of how to display author information for the author the archive is displaying: https://codex.wordpress.org/Author_Templates