[Resolved] Problem in view post author

Hi, Amit here, I am the Toolset Support Manager, our current ticket queue is calm and I'd like to encourage you to use our new chat support option

In order to try it out please notice that when you open a ticket (while there's availability) you will be able to choose between chat and a normal ticket, both lanes lead to the same supporters and if we decide in chat that the issue needs more time we'll transform it into a normal email ticket for you, so nothing is lost

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.

This thread is resolved. Here is a description of the problem and solution.

Problem:

I've a custom post type "accommodation". I've a field repetable group "room" taht is displayed in the accommodation page.

Each accommodation has a different author (accommodation manager role).

In mt WP backend I've add as administrator some rooms fro some accommodation.

The problem is that now I'm the author of this room and not the accommodation manager.

How can I set it?

Solution:

It is expected result, Toolset repeatable group is actually a hidden custom post type, and you are using administrator to setup the "room" item in admin side, so the "room" item author will be setup as current user: administrator.

In your case, I suggest you try these: When you edit a single "accommodation", add/edit a room item(post), save the "accommodation" post, use WordPress action hook "save_post" to trigger a custom function, in this function update the room post's author as "accommodation" post author. For example:

https://toolset.com/forums/topic/problem-in-view-post-author/#post-1146368

Relevant Documentation:

https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 3 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#1146342

Hi,

I've a custom post type "accommodation".
I've a field repetable group "room" taht is displayed in the accommodation page.

Each accommodation has a different author (accommodation manager role).

In mt WP backend I've add as administrator some rooms fro some accommodation.

The problem is that now I'm the author of this room and not the accommodation manager.

How can I set it?

Please conider that rooms are not custom post but only fields and I've set it via backend

#1146368

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi,

It is expected result, Toolset repeatable group is actually a hidden custom post type, and you are using administrator to setup the "room" item in admin side, so the "room" item author will be setup as current user: administrator.

In your case, I suggest you try these:
When you edit a single "accommodation", add/edit a room item(post), save the "accommodation" post, use WordPress action hook "save_post" to trigger a custom function, in this function update the room post's author as "accommodation" post author. For example:

function update_room_author( $room_id ) {
	$room_cpt_slug = 'room-group';
    if ( get_post_type( $room_id ) == $room_cpt_slug ) {
        // Get accommodation from RelatedItem
		$accommodation_id = toolset_get_related_post( $room_id, $room_cpt_slug, 'parent' );
        $accommodation_post = get_post($accommodation_id);
      	$accommodation_author_id = $accommodation_post->post_author;
        //  update room post author
      	$args = array(
          'ID'=> $room_id, 
          'post_author' => $accommodation_author_id,
        );
		remove_action( 'save_post', 'update_room_author', 10 );
        wp_update_post( $args );
		add_action( 'save_post', 'update_room_author', 10, 2 );
     }   
}
add_action( 'save_post', 'update_room_author', 10, 2 );

Please replace "room-group" with your repeatable group room slug, you can get it by editing repeatable group "room", option value "Group slug".

#1146589

Perfect! Thank you for your help Luo

#1146777

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

You are welcome