WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Richzendy
    Member
    Posted 2 months ago #

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

    I have a custom post with a custom template page:

    http://www.example.com/calendar/

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

    http://www.example.com/calendar/date1
    http://www.example.com/calendar/date2
    http://www.example.com/calendar/date3

    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):

    http://www.example.com/stats/race

    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:

    http://www.example.com/stats/race/date1
    http://www.example.com/stats/race/date2
    http://www.example.com/stats/race/date3

    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
    Member
    Posted 2 months 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
    Member
    Posted 2 months ago #

    I change my item url to this:

    http://www.example.com/stats/race/?stat=date1

    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:

    if($parametro){
    
    //args
    $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.]

Reply

You must log in to post.

About this Topic

Tags

No tags yet.