• Resolved ppmakki

    (@ppmakki)


    Hello guys!

    I am a newbie in theme developing in wordpress so I apologize in advance if I am doing something wrong here and if I am a little confusing with my questions.

    Here is my problem..

    I registered custom post type called transports. Here is the code:

    add_action( 'init', 'transports_init' );
    // Custom post type Transports
    function transports_init() {
    
    	$labels = array(
    		'name'               => _x( 'Transports', 'post type general name', 'your-plugin-textdomain' ),
    		'singular_name'      => _x( 'Transport', 'post type singular name', 'your-plugin-textdomain' ),
    		'menu_name'          => _x( 'Transports', 'admin menu', 'your-plugin-textdomain' ),
    		'name_admin_bar'     => _x( 'Transport', 'add new on admin bar', 'your-plugin-textdomain' ),
    		'add_new'            => _x( 'Add New', 'book', 'your-plugin-textdomain' ),
    		'add_new_item'       => __( 'Add New Transport', 'your-plugin-textdomain' ),
    		'new_item'           => __( 'New Transport', 'your-plugin-textdomain' ),
    		'edit_item'          => __( 'Edit Transport', 'your-plugin-textdomain' ),
    		'view_item'          => __( 'View Transport', 'your-plugin-textdomain' ),
    		'all_items'          => __( 'All Transports', 'your-plugin-textdomain' ),
    		'search_items'       => __( 'Search Transports', 'your-plugin-textdomain' ),
    		'not_found'          => __( 'No transports found', 'your-plugin-textdomain' ),
    		'not_found_in_trash' => __( 'No transports found in Trash', 'your-plugin-textdomain' )
    	);
    
    	$args = array(
    		'labels'             => $labels,
    		'public'             => true,
    		'publicly_queryable' => true,
    		'show_ui'            => true,
    		'show_in_menu'       => true,
    		'query_var'          => true,
    		'rewrite'            => array( 'slug' => 'transport' ),
    		'capability_type'    => 'post',
    		'hierarchical'       => false,
    		'menu_icon' 		 => 'dashicons-location-alt',
    		'supports'           => array(
    			'title',
                'editor',
                'excerpt',
                'trackbacks',
                'custom-fields',
                'comments',
                'revisions',
                'thumbnail',
                'author',
                'page-attributes',)
    	);
    
        register_post_type( 'transports', $args );
    }

    After that I made a query to show me all of the transports I manually add. Transports have 4 custom fields so in the query I only show the meta. Here is the code of my query:

    <?php
     $query = new WP_Query( array('post_type' => 'transports', 'posts_per_page' => 100 ) );
       if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
       <a href="<?php the_permalink() ?>"><?php the_meta(); ?>
       <?php wp_reset_postdata(); endwhile; endif; ?>

    As you can notice I am displaying posts as links. What I want to do is that link to take me to the some other page or template or whatever it should be and to show me only the post I clicked on.

    How can I do that? Please write me the whole code and where I should write that code also.

    Thank you in advance.

Viewing 1 replies (of 1 total)
  • Thread Starter ppmakki

    (@ppmakki)

    All I had to do was to make single.php page with following code:

    <?php the_post(); ?>
     <?php the_meta(); ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Link to a single post of custom post type’ is closed to new replies.