Hi Devin!
Hope you’re having a good day!
The error message is letting you what is wrong:
PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘course’ not found or invalid function name
I did add some emphasis to the part that matters most. What that means is that the function course is not defined anywhere. Part of that reason is because the function call_use_func_array() is looking for this function to run. The reason this function is looking for that is because when you add a filter or an action you are trying to link a function to that.
So, in this case admin_init is looking for a function called course and because it cannot find it, it gives that error.
Generally you want to avoid registering shortcodes, post types, or taxonomies in a theme. The best way is using a plugin so it won’t be lost when the theme is switched.
To give a code example, if you wanted to do the above you would do something like:
add_action( 'admin_init', 'jc_reg_posttype' );
function jc_reg_posttype() {
// run my needed code here
}
Hope that helps!
Thanks Jose for the feedback.
I completely understand, but want to make changes to the code to stop the errors. So, would you suggest that I empty the function to;
add_action( 'admin_init', '' );
register_post_type( 'course',
array(
'labels' => array(
'name' => __( 'Courses' ),
'singular_name' => __( 'Courses' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail'),
)
);
If because the call can’t see the function, can I confirm that no code is running from that function. If that is the case, removing the function call syntax would have no effect on the rest of the theme as it is already not being used.
Or do you have other ideas?
thanks again for your help.
Happy to help Devin!
So, would you suggest that I empty the function to;
Not sure if that will work seeing how you are not passing it a callback function. The second part needs to be a valid function that you create in order to register your post type.
I’ll leave you with a few helpful links:
https://codex.ww.wp.xz.cn/Function_Reference/register_post_type
https://developer.ww.wp.xz.cn/reference/functions/add_action/
http://docs.presscustomizr.com/article/26-wordpress-actions-filters-and-hooks-a-guide-for-non-developers
OK, I think I have it.
I will need to create a function in the function.php file that will register the post type.
This should resolve my error issue, correct ?
Thanks.
Adding the function worked !! Thanks Jose