[resolved] get a post from a new template page (3 posts)

  1. Richzendy
    Posted 1 year ago #

    Hi, i don't know how explain this, but i will try:

    I have a custom post with a custom template page:


    This works and will show a list from my custom posts named calendar


    This Works also and shown events with date1, date3 and date3.

    But i want add a new extra field to my custom post named calendar, i created two new pages (stats is a page parent by race but for the moment is not important):


    The race page has a new template page and only shown a list by calendar posts with my new custom field (named stats), and works, the links to each item has this format:


    In this moment i get 404 error by each url, i can't use single template page here, how i can show a custom template by each item?, i want only show the stat field to each item in this pages.

    Exists other choice to make that?

    Any help can be appreciated.

  2. bcworkz
    Posted 1 year ago #

    The combination of query vars resulting from both a race and calendar request results in a query that cannot return anything, hence the 404. If the URL must be of that format, use the Rewrite API to inform WP how to properly parse the URL in order to return the correct post.

    If the URL format is not needed to be of that form, you could achieve the results you desire by altering the stats page to use simple calendar URLs, then altering the single-calendar.php template to display the stat field. If the stat field is not always appropriate, the template can contain a conditional statement to only show the field when appropriate.

  3. Richzendy
    Posted 1 year ago #

    I change my item url to this:


    And in my template i put this in the start:

    $parametro = $_GET['stat'];

    Them you can get the url param, date1

    You can use this param in the whole template and build your filter, for example:

    $args = array(
    	'posts_per_page' => 1,
    	'post_type'      => 'calendario',
    	'name'           => $parametro,
    	'post_status'    => 'publish'
    $the_query = new WP_Query( $args );
    <?php // THE LOOP ?> 
    <? } else { ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.