Skip to content

Instantly share code, notes, and snippets.

@lelandf
Created March 28, 2020 00:02
Show Gist options
  • Save lelandf/ade5aa6132bf4035b5098f826456082e to your computer and use it in GitHub Desktop.
Save lelandf/ade5aa6132bf4035b5098f826456082e to your computer and use it in GitHub Desktop.
/* No warranty or support offered. Please use at your own risk */
function leland_learndash_update_course_meta() {
$course_args = array(
'post_type' => 'sfwd-courses',
// Please be careful with unbounded queries
// This is not going to work well if you have a lot of courses
// Test on a staging/dev server first!
'posts_per_page' => -1,
);
$course_query = new WP_Query( $course_args );
if ( $course_query->have_posts() ) {
while ( $course_query->have_posts() ) {
$course_query->the_post();
// Get the course meta
$meta = get_post_meta( $course_id, '_sfwd-courses', true );
// Update access mode to "Buy Now"
$meta['sfwd-courses_course_price_type'] = 'paynow';
// Change price to "4"
$meta['sfwd-courses_course_price'] = '4';
update_post_meta( get_the_ID(), '_sfwd-courses', $meta );
}
}
}
add_action( 'init', 'leland_learndash_update_course_meta' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment