apply_filters( 'learndash_post_args', array $post_args )
Filters post arguments used to create the custom post types and everything associated with them.
Description #
Parameters #
- $post_args
-
(array) An array of custom post type arguments.
Source #
Examples #
Note: Extended code example below not guaranteed, you may need to consult with a developer
<?php
/**
* Example usage for learndash_post_args filter.
*/
add_filter(
'learndash_post_args',
function( $post_args = array() ) {
if ( ( ! isset( $post_args['sfwd-certificates']['cpt_options']['supports'] ) ) || ( ! is_array( $post_args['sfwd-certificates']['cpt_options']['supports'] ) ) ) {
$post_args['sfwd-certificates']['cpt_options']['supports'] = array();
}
$post_args['sfwd-certificates']['cpt_options']['supports'] = array_merge( $post_args['sfwd-certificates']['cpt_options']['supports'], array( 'custom-fields' ) );
// always return the $post_args array
return $post_args;
},
10,
1
);
add_filter(
'learndash_post_args',
function( $post_args = array() ) {
$post_args['sfwd-courses']['cpt_options']['show_in_nav_menus'] = true;
$post_args['sfwd-lessons']['cpt_options']['show_in_nav_menus'] = true;
$post_args['sfwd-topic']['cpt_options']['show_in_nav_menus'] = true;
$post_args['sfwd-quiz']['cpt_options']['show_in_nav_menus'] = true;
$post_args['sfwd-question']['cpt_options']['show_in_nav_menus'] = true;
// always return the $post_args array
return $post_args;
},
10,
1
);
// Add Custom Field Support to LD Course post type sfwd-courses.
add_filter(
'learndash_post_args',
function( $post_args = array() ) {
// Other LearnDash post types
// Lessons - sfwd-lessons
// Topics - sfwd-topic
// Quizzes - sfwd-quiz
if ( isset( $post_args['sfwd-courses']['cpt_options']['supports'] ) ) {
if ( ! is_array( $post_args['sfwd-courses']['cpt_options']['supports'] ) ) {
$post_args['sfwd-courses']['cpt_options']['supports'] = array( 'custom-fields' );
} elseif ( ! in_array( 'custom-fields', $post_args['sfwd-courses']['cpt_options']['supports'] ) ) {
$post_args['sfwd-courses']['cpt_options']['supports'][] = 'custom-fields';
}
} else {
$post_args['sfwd-courses']['cpt_options']['supports'] = array( 'custom-fields' );
}
// always return the $post_args array
return $post_args;
},
10,
1
);
add_filter(
'learndash_post_args',
function( $post_args = array() ) {
// LearnDash v2.5.3 LEARNDASH-1388
if ( LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Courses_Builder', 'shared_steps' ) != 'yes' ) {
$post_args['sfwd-lessons']['cpt_options']['show_in_nav_menus'] = true;
$post_args['sfwd-topic']['cpt_options']['show_in_nav_menus'] = true;
$post_args['sfwd-quiz']['cpt_options']['show_in_nav_menus'] = true;
}
// always return the $post_args array
return $post_args;
},
10,
1
);
add_filter(
'learndash_post_args',
function( $post_args = array() ) {
// Example 1
// As of LD v2.3 this all custom post types were excluded from search
// We want to include Courses and Lesson in the WP search results.
if ( isset( $post_args['sfwd-courses']['cpt_options']['exclude_from_search'] ) ) {
$post_args['sfwd-courses']['cpt_options']['exclude_from_search'] = false;
}
if ( isset( $post_args['sfwd-lessons']['cpt_options']['exclude_from_search'] ) ) {
$post_args['sfwd-lessons']['cpt_options']['exclude_from_search'] = false;
}
// always return the $post_args array
return $post_args;
},
10,
1
);
add_filter(
'learndash_post_args',
function( $post_args = array() ) {
if ( isset( $post_args['sfwd-certificates']['slug_name'] ) ) {
$post_args['sfwd-certificates']['slug_name'] = 'ld-certificates';
}
// always return the $post_args array
return $post_args;
},
10,
1
);
Changelog #
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |