• Olá!
    Eu criei um novo Post Type “Sketchs” e queria exibir apenas seus posts na index.

    Então. Utilizei o

    <?php if (have_posts()): while (have_posts()) : the_post();?>
    post
    <?php endwhile; else:?>
    <?php endif;?>

    para chamar, só que chama os posts publicados no Post Type padrão do wordpress.

    Alguém tem a solução? :/

Visualizando 2 respostas - 1 até 2 (de um total de 2)
  • Você tem que fazer isso via WP_Query.
    See more in: https://codex.wordpress.org/Class_Reference/WP_Query

    Ou faz assim:

    <?php
        $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
        $args = array(
            'post_type' => 'sketchs',
            'posts_per_page' => '20',
            'paged' => $paged,
            'order' => 'DESC',
            'orderby' => 'date'
        );
        $query = new WP_Query($args);
    
        if ( $query -> have_posts() ){
            while ( $query -> have_posts() ){
                    $query -> the_post();
                    echo the_title();
                    echo the_content();
            }
        }else{
            echo "Do Something...";
        }
    
        wp_reset_postdata();
    ?>

    Ai o CSS é com vc.

    A forma que uso é assim:

    functions.php

    <?php
    add_action('init', 'wp_init');
    
    function wp_init() {
    	nomecustom_register_post_types();
    }
    
    function nomecustom_register_post_types() {
    	register_post_type('nomecustom',
    		array(
    			'labels' => array(
    				'name' => 'Nomes',
    				'singular_name' => 'Nome',
    				'add_new' => 'Adicionar Nome',
    				'edit_item' => 'Editar Nome'
    			),
    			'public' => true,
    			'has_archive' => true,
    			'supports' => array('title', 'editor', 'thumbnail')
    		)
    	);
    }

    loop.php

    <?php
    $nomecustom = new WP_Query(
    	array(
    	  'post_type' => 'nomecustom',
    	  'posts_per_page' => 100
    	 )
    	);
    
    while( $nomecustom->have_posts() ) : $nomecustom->the_post();
    ?>
    
    post
    
    <?php endwhile; ?>
Visualizando 2 respostas - 1 até 2 (de um total de 2)
  • O tópico ‘Exibir posts de um outro Post Type’ está fechado para novas respostas.