Skip Navigation

[Resolved] View not working correctly / creating users

This support ticket is created 6 years, 4 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 10 replies, has 2 voices.

Last updated by PZ 6 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#600015

PZ

I created a site for posting two kinds of custom post types: ads and showcases. The site allows to add them in two ways: as a logged-in user and as non logged-in user.

I also applied views to the post templates: one which allows logged-in users to display their company's showcase post (if they have one) in the ad post and another which allows to display user's ads in the showcase post.

With logged-in users it works fine.

With non logged-in users there seems to be something wrong:

When a non logged-in user posts an ad the view assigns the first-on-the-list showcase to that post and displays it. Even though authors of both posts don't match (and I set in a view that the the displayed showcase author must be the same as the ad post author). When I edit the ad post, change the author, and save changes then it works correctly... in a way - it assigns the first showcase with the same author (as it should, I know).

The thing is that the author of all non logged-in user posts (both ads and showcases) is by default made the first user from the users list with the role other than "subscriber". In my case this is the first "author" from the users list in my site (in alphabetical order).

I need to keep the functionality of adding both custom post types for non logged-in users and I'd like to:

either create two default users: one for all ads posted by non logged-in users and one for showcases added the same way and auto assign them when creating posts or auto create a unique user for each post added by a non logged-in user.

Could you help me with it?

#600097

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - that is strange. Could you please share problem URL where you are listing your post same as author equal to logged in user.

either create two default users: one for all ads posted by non logged-in users and one for showcases added the same way and auto assign them when creating posts or auto create a unique user for each post added by a non logged-in user.
==> Well - you should create two different user with two different role and assign them as post author when you submit your post.

Also,
- are you using CRED form to create post?

#602473

PZ

I am sorry for very late reply, couldn't do it earlier.

So I tried to solve the problem as you mentioned, except I thought it would be enough to create only one user - for ads posted by non logged-in users. It works - when a random guest posts an ad there's automatically a ghost author assigned to it. The showcases I made available only for logged in users so the problem disappeared.

As you remember: I applied views to the post templates: one which allows logged-in users to display their company's showcase post (if they have one) in the ad post and another which allows to display user's ads in the showcase post.

Now, when a non logged in user posts an ad, the view displays a showcase which does not belong to it. The author of the ad post is my ghost-author and the author of the showcase is some user who created it. How is t possible?

"Could you please share problem URL where you are listing your post same as author equal to logged in user" - I actually added a post author filter <<Select posts with the author the same as the page where this View is shown.>>
These are the views:
hidden link
hidden link

The above views are inserted in, adequately, ads template and showcase template:
hidden link
hidden link

What is important - the problem appears only when a non logged in user posts an ad, and I do not touch it. It disappears when I make changes to that post, e.g. when I change it to draft. When I publish it again, everything is fine. I keep making those changes because I don't want to keep it visible like this, but every time a new post is added, it happens.

So I created a test ad post for you so you can look at it untouched:
hidden link
hidden link

And as you will see the author of the ad is "autoghost". But if you look at the back-end of the showcase it displays at the bottom:
hidden link
hidden link
you'll see the author is different.

Whew, I hope I made it understandable...please help.
And yes, I use CRED.

#602531

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

So I created a test ad post for you so you can look at it untouched:
hidden link
hidden link
And as you will see the author of the ad is "autoghost".
==> Yes - I confirm that above post author is set as "autoghost"

Still - I've doubt what the issue is - do you mean that the above post with "autoghost" should not display on frontend?

#602535

PZ

No, I mean something else.

If you scroll down to the bottom of the ad post in front-end there is a card that links to a company showcase. And if you look at that showcase from back-end (which i provided) you'll see that the author is different, so technically it should not be displayed (I have not intended this).

#602545

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - the issue is from your cache plugin "light speed cache" - I deactivated it.

I then resave the following post:
=> hidden link

And I've deleted and readded the post author query filter from your view's query filter section and also I've uncheck the checkbox "Nie uwzględniaj bieżącej strony w wynikach zapytania" from your view from section your view's "Opcje zapytania" and I can see now it's not displaying any post at bottom of the page.

#602562

PZ

"Well - the issue is from your cache plugin "light speed cache" - I deactivated it."
I am 100% sure that this is not that plugin's fault. I tested it myself and I deactivated all the plugins except toolset plugins. The problem remains. When I post a new ad, the showcase of different user appears at the bottom.

There is one way to fix this - if, in wordpress post editing page, I change the author of the post manually, save and then change the author back to "autoghost". When I do that the showcase from the bottom disappears. This works regardless of whether all the plugins are activated or deactivated.

So can you help me any further.

BTW. The page is on LiteSpeed hosting (hidden link). The litespeed cache plugin must be activated for this type of hosting. So I turned it back on. It is not so easy to deactivate the plugin just by clicking "deactivate".

#602568

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

There is one way to fix this - if, in wordpress post editing page, I change the author of the post manually, save and then change the author back to "autoghost". When I do that the showcase from the bottom disappears. This works regardless of whether all the plugins are activated or deactivated.
==> Yes - that is what I did it when I told you that:

I then resave the following post:
=> <em><u>hidden link</u></em>

Could you please tell me from where I can post a new Ad and also confirm that when you post a new Ad - what user assigned to it?

#602571

PZ

Sure, you can add a post from here:
hidden link

Video instruction is here: hidden link (in Polish, but you can see how to fill in the fields).

Important - you need to post the ad as a non logged-in user.

As for the author... honestly, I don't know how WordPress assigns the users to the posts, but in case of those ad posts it always chooses the first user with the role "author" from my users list and it is the user "autoghost".

#602621

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now. I've added following code to your current theme's functions.php file to set post author for created using the CRED form ID 1290.

add_action('cred_save_data','func_custom_post_author',10,2);
function func_custom_post_author($post_id,$form_data) {
	
    if ($form_data['id']==1290 and !get_current_user_id() ) {
		
     $my_post = array(
      'ID'           => $post_id,
      'post_author' => 25    // autoghost user ID
	  );
   
// Update the post into the database
  wp_update_post( $my_post );
    }
}

If will set the post author = 25 (autoghost user ID) to every post created using the CRED form ID 1290 and when user is not logged in.

Could you please check now and let me know it works as expected.

#602746

PZ

Great! It works.
Thank you very much for your time Minesh.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.