Ask your WordPress questions! Pay money and get answers fast! (more info)

Change author on custom post types WordPress

  • REFUNDED

Hello,

I need assistance with code to change the author on custom post types.

What I've found
https://wordpress.stackexchange.com/questions/59314/how-do-i-change-the-author-of-a-custom-post-type

This is in french and author says to use a filter
https://wp-customerarea.com/support/topic/cpt-private-files-modify-the-supports/

Thank you for checking.

Answers (6)

2017-05-19

Cesar Contreras answers:

I think this is what you should do:

in order to add author support to a custom post type you need to added ‘author’ to the supports array when registering the post type:

'supports' => array('title', 'editor', 'thumbnail', 'comments', 'author'),

This will activate author box on the edit screen. After registering author to cpt you need to activate author from edit screen option ( top of the edit screen where you can enable/disable all metabox ) to display authorbox on the edit screen.

Here is the link to the documentation to create CPT:
https://codex.wordpress.org/Function_Reference/register_post_type#Arguments

2017-05-20

mod mi answers:

Hi viradesign,

You don't mention how you register your custom post types but I'd strongly recommend the Custom Post Type UI plugin to save you time and effort from registering/editing your post types, custom taxonomies etc. You can enable disable options and update them via a simple UI. And it even has a feature to export the custom post types code if you'd prefer not to use it permanently. https://wordpress.org/plugins/custom-post-type-ui/

2017-05-20

Arnav Joy answers:

you have all posts created and want to change author of the all posts ?


Creativira comments:

Yes, all CPTs were created in a plugin called WP Customer Area with many addons.


Arnav Joy comments:

you have more then one cpt's ?


Creativira comments:

more than one CPT.

2017-05-20

Luis Abarca answers:

If you want to update author for all items of a custom post type, you can run a query on your wp_posts table like below.

<?php

function update_authors_for_post_type( $author_id, $post_type ) {
global $wpdb;

$sql = 'UPDATE ' . $wpdb->prefix . ' SET post_author=%d';

$wpdb->query( $wpdb->prepare( $sql, $author_id ) );
}

update_authors_for_post_type( 1, 'your_custom_post_type );


Creativira comments:

Don't understand 'run a query'.


Luis Abarca comments:

Hi, it's a function to update post author on specific custom post type.

Example: Lets say, i want to assign all custom post types events to author Jhon with user ID 4.

Will call the function like below.


update_authors_for_post_type(4, 'events');

2017-05-21

Francisco Javier Carazo Gil answers:

Good afternoon,

It seems that there is a filter called: cuar/private-content/files/register-post-type-args

Which is the one responsible of customize it.

It should be this one:

add_filter( 'cuar/private-content/files/register-post-type-args', 'set_authors_cpt' ) ;
function set_authors_cpt($args){
$args['supports'] = array( 'title', 'editor', 'author' );
return $args;
}


Creativira comments:

This shows a dropdown but with only admins as options. Would like to be able to choose other roles.

2017-05-22

Mohammad Kashif Nadeem answers:

1. First you need to add this line into your custom post type code

"supports" => array( "title", "editor", "thumbnail", "excerpt", "trackbacks", "custom-fields", "comments", "revisions", "author", "page-attributes", "post-formats" ),

If you generated custom post type through wordpress plugin > Custom Post Type UI then you have to check Author check box. (please see screenshot section no.1)

2. Now go into your custom post type and click on the top right Button > Screen Option. In this pane please select Author. (please see screenshot section no.2)

3. Scroll down your page... on the button you would have a section Author. From here you can transfer authorship to any author. (please see screenshot section no.3)


Creativira comments:

Thank you. That doesn't help.


Mohammad Kashif Nadeem comments:

Np
Good Luck
Have a Great Day!