我有一个帖子类型“contracts”,在一个特定的页面模板上,我想显示meta\\u键“distributor\\u email”与当前用户的电子邮件匹配的帖子。尝试了以下两种方法,都返回了500内部服务器错误。这可能意味着我错过了一些非常基本的东西,但我还没有弄清楚,我真的很想再多看一眼。
<?php
$userEmail;
if ( wp_get_current_user() instanceof WP_User ) {
$userEmail = wp_get_current_user()->user_email;
}
$users_query = new WP_Query( array(
\'post_type\' => \'contracts\',
\'meta_key\' => \'distributor_email\',
\'meta_value\' => $userEmail,
) ); ?>
<?php if ( $users_query->have_posts() ): ?>
<?php while ( $users_query->have_posts(): $users_query->the_post() ) ?>
<div class="loginContract">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="pink"><?php the_title(); ?></a>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
这是我第二次尝试。。
<?php
$userEmail;
if ( wp_get_current_user() instanceof WP_User ) {
$userEmail = wp_get_current_user()->user_email;
}
$users_query = new WP_Query( array(
\'post_type\' => \'contracts\',
\'meta_query\' => array(
array(
\'key\' => \'distributor_email\',
\'value\' => $userEmail,
\'compare\' => \'=\',
),
),
) );
?>
<?php if ( $users_query->have_posts() ): ?>
<?php while ( $users_query->have_posts(): $users_query->the_post() ) ?>
<div class="loginContract">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" class="pink"><?php the_title(); ?></a>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
谢谢:)