Cum să apelezi un tip de postare personalizat cu WP_Query
27 iun. 2017, 09:29:24
Vizualizări: 31K
Voturi: 1
Cum pot să apelez un tip de postare personalizat cu WP_Query
?
Acesta este tipul meu de postare personalizat. Cum îl pot afișa în codul meu?
<?php
// Conectarea funcției noastre la configurarea temei
add_action( 'init', 'create_post_type' );
add_theme_support('post-thumbnails');
function setup_types() {
register_post_type('mytype', array(
'label' => __('Tipul meu'),
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
'show_ui' => true,
));
}
add_action('init', 'setup_types');
?>

Evan Mendes
11
Toate răspunsurile la întrebare
2
0
$args = array('post_type' => 'mytype' );
$the_query = new WP_Query( $args );
// Bucla
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
/* Restaurare date post originale */
wp_reset_postdata();
} else {
// nu s-au găsit postări
}
Mai multe informații puteți găsi aici: https://codex.wordpress.org/Class_Reference/WP_Query

sebastian_aps
141
27 iun. 2017 09:42:56
0
Sper că acest lucru vă va fi de ajutor.
$args = array(
'post_type' => 'your custom post type here',
'posts_per_page' => 5,
'category' => '',
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
} // end while
} // end if
wp_reset_query();

wplearner
489
27 iun. 2017 10:45:58
Întrebări similare
6
răspunsuri
1
răspunsuri
6
răspunsuri