Home › Toolset Professional Support › [Closed] Managing a plugins' custom post type with Toolset
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 topic contains 10 replies, has 2 voices.
Last updated by Christopher Amirian 3 months, 1 week ago.
Assisted by: Christopher Amirian.
Hi,
I found this thread and documentation about how to manage a custom post type from another plugin with toolset:
https://toolset.com/course-lesson/convert-existing-custom-types-and-fields-to-types-control/
https://toolset.com/forums/topic/manage-custom-post-type-created-by-another-plugin/
However I can't seem to get this to work. The plugin is WP Portfolio by Astra. When I try to create a cpt with the slug "portfolio" it tells me that one is already in use so I can't follow this process.
Tim
Hi Tim,
Please deactivate the plugin and also change the Astra theme to something else so you make sure that there is no code referring to that post type and then try to add the custom post type.
Make sure you have a complete backup of the website before doing so.
Be aware that the method is not a 100% guarantee as there might be some code differences on how the post is created and that might create conflicts later using the plugin.
Thanks.
Quick update: I found the slug was astra-portfolio so deactivate the WP Astra plugin then created a ctp with this slug then reactivated. This worked in that the menu item now shows the name of the cpt I created, and the View shows this name when I select Content Selection. But still nothing appears on the front-end. I noticed that each portfolio item does not have a front end page and no url field on each item, even though I do have publicly_queryable selected.
hidden link
So maybe this plugin has some settings that a are causing toolset to not be able to detect it on some level?
Tim
Hi Tim,
I think you did the steps correctly. So honestly, I am not sure as I am not familiar with the plugin in question.
Maybe if you could contact the plugin developer and ask them if they can give more information?
I am not sure what you should ask them. Maybe if the post type is hidden by default or not?
I have a ticket open with the plugin developer concerning this as well. If you have any questions or thoughts maybe it would be easier if I just add them to that ticket?
Tim
Hi Tim,
What I would ask is if there is any sort of non-standard WordPress practice is used on the custom post creation and if the post type is hidden or not.
Thanks.
Still awaiting their response, but this is what I see in the plugin code for registering this cpt:
public function register_post_and_taxonomies() {
/**
* Register Post Type
*
* Register "Astra Portfolio" post type.
*/
$labels = array(
'name' => _x( 'Portfolio', 'post type general name', 'astra-portfolio' ),
'singular_name' => _x( 'Portfolio', 'post type singular name', 'astra-portfolio' ),
'menu_name' => _x( 'WP Portfolio', 'admin menu', 'astra-portfolio' ),
'name_admin_bar' => _x( 'Portfolio', 'add new on admin bar', 'astra-portfolio' ),
'add_new' => _x( 'Add New', 'new portfolio item', 'astra-portfolio' ),
'add_new_item' => __( 'Add New Portfolio', 'astra-portfolio' ),
'new_item' => __( 'New Portfolio', 'astra-portfolio' ),
'edit_item' => __( 'Edit Portfolio', 'astra-portfolio' ),
'view_item' => __( 'View Portfolio', 'astra-portfolio' ),
'all_items' => __( 'All Portfolio Items', 'astra-portfolio' ),
'search_items' => __( 'Search Portfolios', 'astra-portfolio' ),
'parent_item_colon' => __( 'Parent Portfolios:', 'astra-portfolio' ),
'not_found' => __( 'No Portfolios found.', 'astra-portfolio' ),
'not_found_in_trash' => __( 'No Portfolios found in Trash.', 'astra-portfolio' ),
);
$args = apply_filters(
'astra_portfolio_post_type_args',
array(
'labels' => $labels,
'description' => __( 'Description.', 'astra-portfolio' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'menu_icon' => 'dashicons-portfolio',
'show_in_rest' => true,
'rest_base' => 'astra-portfolio',
'rest_controller_class' => 'WP_REST_Posts_Controller',
'supports' => array( 'title', 'editor', 'thumbnail' ),
)
);
register_post_type( 'astra-portfolio', $args );
/**
* Register Post Meta
*
* For custom post types, this is 'post', for custom comment types, this is 'comment'.
*/
$args = array(
'type' => 'string', // Validate and sanitize the meta value as a string.
'single' => true, // Return a single value of the type. Default: false.
'show_in_rest' => true, // Show in the WP REST API response. Default: false.
);
Hi there,
The code seems to be very standard. I would also ask if there are single posts view that is available by default for that plugin?
That might help as you said, the content can be found in the VFiew, but the result does not show.
Thanks.
The plugin developers are not much help. But I did notice that there are 4 "Types" to choose from when creating a New Portfolio item (Website, Video, Image, Single Page), and it seems only "Single Page" will appear on the front-end with the view. So maybe the other 3 are not set to "Page" which means Views cannot detect them?
I found code like this that targets the Page items:
/**
* Get portfolio type
*
* @since 1.0.2
*
* @return array Portfolio types.
*/
public static function get_portfolio_types() {
$all_types = apply_filters(
'astra_portfolio_add_new_types',
array(
array(
'key' => 'iframe',
'label' => __( 'Website', 'astra-portfolio' ),
),
array(
'key' => 'image',
'label' => __( 'Image', 'astra-portfolio' ),
),
array(
'key' => 'video',
'label' => __( 'Video', 'astra-portfolio' ),
),
array(
'key' => 'page',
'label' => __( 'Single Page', 'astra-portfolio' ),
),
)
);
return $all_types;
}
/**
* Exclude Portfolios
*
* Exclude portfolio items (website, image and video) from the query.
*
* @return void
* @since 1.1.0
*/
public function exclude_portfolios() {
if ( apply_filters( 'astra_portfolio_exclude_portfolio_items', ! is_admin() ) ) {
add_filter( 'posts_where', array( $this, 'where_clause' ), 20, 2 );
add_filter( 'get_next_post_where', array( $this, 'post_navigation_clause' ), 20, 1 );
add_filter( 'get_previous_post_where', array( $this, 'post_navigation_clause' ), 20, 1 );
}
}
/**
* Show the view row action link only for 'Single Page' portfolio type.
*
* @since 1.8.1
* @param string[] $actions An array of row action links. Defaults are
* 'Edit', 'Quick Edit', 'Restore', 'Trash',
* 'Delete Permanently', 'Preview', and 'View'.
* @param WP_Post $post The post object.
* @return array
*/
public function hide_row_actions( $actions, $post ) {
// not portfolio type then return.
if ( 'astra-portfolio' !== $post->post_type ) {
return $actions;
}
$portfolio_type = get_post_meta( $post->ID, 'astra-portfolio-type', true );
return $actions;
}
Hi, any more thoughts on this, or should I just assume it's not really possible?
Thanks,
Tim
Hi Tim,
Unfortunately, there is nothing more that I can share to help here. I would ask you to remove "exclude_portfolios" function and check, but I do not think that has an impact.
I wish I could help more here but it seems there is no way to take over the plugin post type by Toolset.
The topic ‘[Closed] Managing a plugins' custom post type with Toolset’ is closed to new replies.