• Hello everybody,

    I create a Custom Post Type for my projects with a specific input to an external URL of my project. I can display when I’m in the post of my project, through the slug.

    But I’d like to know if it is possible to use the value of an input outside the post?

    Here is my Custom Post Type in functions.php

    add_action('init', 'portfolio');
    function portfolio() {
        register_post_type('portfolio', array(
        'label' => __('Portfolio'),
        'singular_label' => __('Portfolio'),
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'rewrite' => false,
        'query_var' => "portfolio",
        'supports' => array('title', 'editor', 'thumbnail', 'custom-fields')
    ));
    }
    
    function admin_init(){
     add_meta_box("url_portfolio", "Url du portfolio", "url_portfolio", "portfolio", "normal", "low");
    }
    function url_portfolio(){
     global $post;
     $custom = get_post_custom($post->ID);
     $url_portfolio = $custom["url_portfolio"][0];
     ?>
     <input size="70" type="text" value="<?php echo $url_portfolio;?>" name="url_portfolio"/>
     <?php
     }
    function save_custom(){
     global $post;
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
     return $postID;
     }
     update_post_meta($post->ID, "url_portfolio", $_POST["url_portfolio"]);
     }
    
    add_action("admin_init", "admin_init");
    add_action('save_post', 'save_custom');

    Here is my code desired

    <?php wp_reset_postdata(); ?>
    	    <?php query_posts('posts_per_page=-1&post_type=portfolio'); ?>
    		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    		<li class="clearfix">
    			<figure class="left">
    				<a href="<?php echo $url_portfolio;?>"><?php the_post_thumbnail(); ?></a>
    			</figure>
    			<article class="right">
    				<h1><a href="<?php echo $url_portfolio;?>"><?php the_title(); ?></a></h1>
    				<?php the_content() ?>
    			</article>
    		</li>
    		<?php endwhile; ?>
    		<?php endif; ?>

    Thanks.

  • The topic ‘Display a Custom Post Type outside a Custom Post Type’ is closed to new replies.