0

I'm using the parse_request hook to trigger the the_content filter when you're at /sportivity-roster in the url. When I do a var_dump in the if statement where I check the constant it's value, it works, but for some not knowing reason it is not reaching my method which should get triggered in the the_content hook.

add_action('parse_request', 'sportivity_roster_custom_url_handler');
function sportivity_roster_custom_url_handler() {
    global $wp;
    $path = $wp->request;
    if($path === sup::ROSTER_URL) { 
        add_filter('the_content', 'generateView', 1);
    }
}

function generateView($content){
    $weeks = sportivity_roster_get_lessons(array_values(Location::loadAll())[0]->getSportivityApi());
    $index = 0;
    $contents = array();
    foreach($weeks as $week => $lessons) {
        foreach($lessons as $locationId => $lessonsForWeek) {
            $weekSelector = sprintf('.location.%s .week_%s', $locationId, $index);
            $content = sportivity_roster_makeWeek($lessonsForWeek, array(), $weekSelector);
            $contents[$weekSelector] = $content;
            $index++;
        }
    }

    $data = array(
        'lessons' => $weeks,
        'contents' => $contents,
        'lessons_bookable' => false,
    );
    return sup::includeView('roster', $data);
}
3
  • 1
    are you sure that if($path === sup::ROSTER_URL) { is succesful? How have you verified this? Have you checked your PHP error log for warnings that could have caused this? Have you tried replacing the code in your filter with return "it works";? or added a wp_die( 'adding filter' ) in sportivity_roster_custom_url_handler? Does the page at that URL call the_content()?
    – Tom J Nowell
    Nov 8, 2022 at 15:27
  • @TomJNowell inside the if statement I did a var_dump which was successful. Then I tried the return it works, but no success. the wp_die does not work eitherand the custom url handler should return a php template instead
    – Jan
    Nov 8, 2022 at 15:30
  • 1
    what is in the custom PHP template? How is the content being displayed? Note that while the_content calls the filter, grabbing the raw post content via get_the_content or $post->post_content does not
    – Tom J Nowell
    Nov 8, 2022 at 15:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.