我有一个严重的问题:(也许有人能帮我
在我的wordpress页面中注册的用户只有一篇帖子,我创建了名为“ofertas”的自定义post\\u类型。用户只能创建一个RTA。使用此代码在索引上显示oferta标题。php,问题是在所有帖子中显示oferta标题。我只想展示他自己的欧足联头衔(如果他们有)。
<?php
// First loop
while ( have_posts() ): the_post();
author_id = get_query_var(\'author\');
$ofertas = array();
// Second Loop
$i = 0;
$args = array(
\'author\' => $author_id,
\'post_type\' => \'ofertas\'
);
$the_query = new WP_Query( $args );
if ($the_query->have_posts()) :
while ($the_query->have_posts()) : $the_query->the_post(); // check if it has offers, if it has, loop over the offers
$ofertas[$i][\'title\'] = get_the_title(); // or anything you need
$i++;
endwhile; // close the loop
else: // if it has no post
continue; // we don\'t display the post
endif;
wp_reset_postdata();
?>
<div class="post">
<?php
the_title(); // or anything you need
foreach ($ofertas as $oferta):
echo $oferta[\'title\']; // we display the title of the offer
endforeach;
?>
</div>
<?php endwhile; ?>
我使用此代码创建了custom\\u post\\u类型
add_action(\'init\', \'crear_tipo_ofertas\', 0);
function crear_tipo_ofertas() {
$labels = array(
\'name\' => _x( \'Ofertas\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Oferta\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'Ofertas\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Oferta Padre\', \'text_domain\' ),
\'all_items\' => __( \'Ofertas\', \'text_domain\' ),
\'view_item\' => __( \'Ver Oferta\', \'text_domain\' ),
\'add_new_item\' => __( \'Añadir Oferta Nueva\', \'text_domain\' ),
\'add_new\' => __( \'Añadir\', \'text_domain\' ),
\'edit_item\' => __( \'Editar Oferta\', \'text_domain\' ),
\'update_item\' => __( \'Actualizar\', \'text_domain\' ),
\'search_items\' => __( \'Buscar Ofertas\', \'text_domain\' ),
\'not_found\' => __( \'Ofertas no encontradas\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'Ofertas no encontradas en Papelera\', \'text_domain\' ),
);
$rewrite = array(
\'slug\' => \'oferta\',
\'with_front\' => true,
\'pages\' => true,
\'feeds\' => true,
);
$args = array(
\'label\' => __( \'oferta\', \'text_domain\' ),
\'description\' => __( \'Ofertas Spas y Balnearios\', \'text_domain\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'comments\', \'thumbnail\', \'custom-fields\'),
\'taxonomies\' => array( \'category\', \'post_tag\' ),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'menu_icon\' => site_url().\'/wp-content/plugins/my_plugin/images/logo.png\',
\'can_export\' => true,
\'has_archive\' => \'ofertas\',
\'exclude_from_search\' => false,
\'query_var\' => \'ofertas\',
\'rewrite\' => $rewrite,
\'capability_type\' => \'post\',
);
register_post_type(\'ofertas\', $args);
}
add_action(\'init\', \'crear_tipo_ofertas\', 0);