Forums Forums Search & Filter Pro Modify Template to Switch Cases

Viewing 5 posts - 1 through 5 (of 5 total)
  • Anonymous
    #193077

    Hi,

    I am trying to modify the results.php template so that I can display a different loop for my different custom post types. I was trying something along the lines but it doesn’t work. I think my syntax is wrong in the first place. If you have any pointers on the best way to achieve this please let me know.

    <?php $curtype = get_post_type( $post->ID ); switch($curtype){
    case “events”: return ‘events code’;
    break;
    case “venues”: return ‘venues code’;
    break;
    }
    ?>

    many thanks,
    Andrew

    Trevor
    #193102

    Rather than:

    get_post_type( $post->ID )

    try

    get_post_type(get_the_ID())

    Anonymous
    #193108

    Hi Trevor, thanks for the prompt reply, however that’s not the issue. Please look at my stackexchange thread which explains what I am trying to achieve:

    https://wordpress.stackexchange.com/questions/318675/template-loop-add-switch-case-php

    Also another question, doesn’t your results.php need to have wp_reset_postdata(); for best practices?

    Trevor
    #193112

    It does not need it (wp_reset_postdata), no.

    Did you try it using get_the_ID()?

    Anonymous
    #193257

    no worries, i have figured this out.. 🙂

Viewing 5 posts - 1 through 5 (of 5 total)