Php 从数组中的对象获取值Wordpress
我正在尝试向Wordpress网站添加投票功能,可用的插件不符合我的要求 我有一个数组,其中包含另一个带有wp\u post对象的数组(这些是投票的用户)。我需要做的是将当前用户ID与数组对象中的所有post\u作者ID进行比较。我需要这样做,以便我可以向已经投票的用户显示不同的内容。只要知道如何从数组中的对象中获取post\u author值,并将其与当前用户id进行比较,就会有很大帮助。我希望你们能帮助我,提前谢谢 以下是获取阵列的方式:Php 从数组中的对象获取值Wordpress,php,arrays,wordpress,object,Php,Arrays,Wordpress,Object,我正在尝试向Wordpress网站添加投票功能,可用的插件不符合我的要求 我有一个数组,其中包含另一个带有wp\u post对象的数组(这些是投票的用户)。我需要做的是将当前用户ID与数组对象中的所有post\u作者ID进行比较。我需要这样做,以便我可以向已经投票的用户显示不同的内容。只要知道如何从数组中的对象中获取post\u author值,并将其与当前用户id进行比较,就会有很大帮助。我希望你们能帮助我,提前谢谢 以下是获取阵列的方式: <?php $my_post_meta = g
<?php $my_post_meta = get_post_meta($post->ID, 'supporters', false);
echo print_r($my_post_meta); ?>
试试这个:
<?php
$my_post_meta = get_post_meta($post->ID, 'supporters', false);
$current_user_ID = get_current_user_id();
foreach( $my_post_meta[0] as $post_object ) {
if( $post_object->ID == $current_user_ID ) {
// The current user has voted
}
}
?>
<?php
$my_post_meta = get_post_meta($post->ID, 'supporters', false);
$current_user_ID = get_current_user_id();
foreach( $my_post_meta[0] as $post_object ) {
if( $post_object->ID == $current_user_ID ) {
// The current user has voted
}
}
?>