1

I am trying to use the following to concatenate a function's output to the post content:

function bottom_content($content) {
    global $post;
    $content .= course_resources($post->ID);
    return $content;
}
add_filter('the_content', 'bottom_content');

function course_resources($id) {
    $course = get_post_meta($id); 
    $course['wpcw_associated_module'][0];                       
    global $wpdb;

    // query for parent_id
    $course_id = $wpdb->get_row('SELECT '.$wpdb->prefix.'wpcw_courses.course_id FROM '.$wpdb->prefix.'wpcw_modules INNER JOIN '.$wpdb->prefix.'wpcw_courses ON '.$wpdb->prefix.'wpcw_modules.parent_course_id='.$wpdb->prefix.'wpcw_courses.course_id WHERE '.$wpdb->prefix.'wpcw_modules.module_id ='.$course["wpcw_associated_module"][0].'', ARRAY_A);
    // $course_id = $wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'wpcw_modules INNER JOIN '.$wpdb->prefix.'wpcw_courses ON '.$wpdb->prefix.'wpcw_modules.parent_course_id='.$wpdb->prefix.'wpcw_courses.course_id WHERE '.$wpdb->prefix.'wpcw_modules.module_id ='.$course["wpcw_associated_module"][0].'', ARRAY_A);

    $upload_dir = wp_upload_dir();                      
    $resource_path = $upload_dir["basedir"].'/resources/Sharepoint-Videos-Resources-'. $course_id["course_id"].'.zip';

    if (file_exists($resource_path)) {
        $resource_link = $upload_dir["baseurl"]. '/resources/Sharepoint-Videos-Resources-'. $course_id["course_id"].'.zip';
        echo '<div style="text-align:center;font-size:14px;background:#dedede;color:#777;border:1px solid #bbb;padding:20px 10px 20px;"><a href="'. $resource_link .'"><button style="font-size:16px;background:#4f8a3f;box-shadow:none;border:1px solid #3F803C;color:#f0f0f0;padding:10px 20px;"><i class="fa fa-download fa-1x"></i> Resource Files</button></a> </div>';
    }
}

The desired outcome is for the <div> containing the button to be placed at the bottom of the post content, but no matter what priority I assign to the add_filter, the output is always at the top of the content.

What am I missing?

2

Your function needs to return the result. echo just outputs it into a page source and no result is produced to be concatenated.

1
  • Of Course! And I feel truly foolish. Thank you Rarst. – Requin Creative Feb 4 '15 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.