Support » Plugin: Custom Content Shortcode » CPT TERMS FROM URL

  • Great Plug in!!!!
    I am using a CPT with a auto generated content that uses wild cards to replace location ( geographical text and genres ( eg. Blues ) I have added a code in below using one term from the taxonomy in the example below (term=blues-band). This pulls out all the blues bands and randomly displays a post count of 3.

    Instead of adding these all manually. Is there a way I can code in from the url to add in the relevant term to the code?

    Thanks in advance.

    http://www.themorrisagency.co.uk/band-hire/bedfordshire/blues-band/

    EXAMPLES OF THE BANDS YOU CAN BOOK
    [loop type=bands-to-hire taxonomy=Genres term=blues-band count=3 orderby=random]
    [field thumbnail]
    [field genres]
    [field title-link]
    [field excerpt]

    [/loop]

    • This topic was modified 10 months, 3 weeks ago by  agentmorris1.
Viewing 7 replies - 1 through 7 (of 7 total)
  • I have struggled to do this very same thing. In the end I moved to Pods, among other reasons because of its Autotemplate system, it does exactly what you are asking for using their [pods] shortcode, similarly to [loop].

    So @mrfoxtalbot you don’t use CPT or CF ?

    Hi,

    Take a look at the “Query variables” reference at the “Pass” tab.

    You can pass the URL route to the loop. I use it like this:

    URL of the page: http://www.domain.com/events/racing/

    [pass global=route]
    [loop type={FIELD_1} category={FIELD_2} count=3]
    [field link]
    [/loop]
    [/pass]

    This outputs 3 postlinks of the cpt “events” with the category “racing”.

    Hi Peter, where would you place that conde?
    Would you do echo do_shortcode in a theme template?

    If you use the “Meta shortcode” functionality of the plugin (first you have to enable it under settings), you can put your code in a “post” of that post type and use the “single” shorcode elsewhere.

    Because in my case I only need it on some (not all) pages, I put the shorcode in the content area of the page. But you can also use the “do_shortcode” function in the page template.

    If you want to limit the output of the loop to special pages, you can use an if-statement like:
    [if route_1=events]Put the pass and loop shorcode in here[/if]

    Or:

    [switch route]
      [when events/*]Put the pass and loop shorcode for events pages in here[/when]
      [when example/*]Shortcode for other page..[/when]
    [/switch]

    This is great @peterpolow
    I have tried it as

    [pass global=query fields=Genres]
    [loop type=bands-to-hire orderby=rand category='{GENRES}’ count=3 ]
    [field thumbnail]
    [field genres]
    [field title-link]
    [field excerpt]
    [/loop]
    [/pass]

    But doesnt pick up the relevant band genre and display them eg.http://www.themorrisagency.co.uk/band-hire/bedfordshire/blues-band/

    I tried the

    [pass global=route]
    [loop type={FIELD_1} category={FIELD_2} count=3]
    [field link]
    [/loop]
    [/pass]

    But didnt seem to work. Maybe I am missing something?

    Yes, I think you’re missing something. My example was for my user case.

    If you want to pull the category slug from the url of the page you’re putting de “loop shortcode” in, then you have to pass only the part of the URL you need in the loop.

    If you want to get work the loop in the page with the URL http://www.themorrisagency.co.uk/band-hire/bedfordshire/blues-band/ and you need the part of the URL where the slug is “blues-band”, you have to pass “field_3” to the loop.

    In your case:
    Page URL: http://www.themorrisagency.co.uk/band-hire/bedfordshire/blues-band/
    Loop on that page:

    [pass global=route]
    Display the output of the fields you pass (for example): 
    Field 1: {FIELD_1} 
    Field 2: {FIELD_2}
    Field 3: {FIELD_3}
    [loop type=bands-to-hire taxonomy=Genres term={FIELD_3} count=3]
    [field link]
    [/loop]
    [/pass]
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘CPT TERMS FROM URL’ is closed to new replies.