Modify Template to Switch Cases

Forums › Forums › Search & Filter Pro › Modify Template to Switch Cases

  • This topic has 4 replies, 2 voices, and was last updated 8 years ago by Anonymous.
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)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.