在Wordpress中删除自定义元字段值的问题

时间:2018-07-26 14:59:43

标签: wordpress wordpress-theming

我在wordpress中创建了一个类似的系统。我已经完成了一个页面,其中将列出用户所有喜欢的帖子。 http://learnwordpresspro.com/like-front-end/我想保留一个删除按钮,该按钮也会从此列表中从前端删除类似内容。我很困惑。为了显示帖子列表,我完成了以下代码。我想保留一个删除按钮,该按钮需要像提交时一样删除帖子

<table class="form-table">
    <tr>
        <th><label for="user_likes"><?php _e( 'You Like:', 'YourThemeTextDomain' ); ?></label></th>
        <td>
        <?php
        $types = get_post_types( array( 'public' => true ) );
        $args = array(
          'numberposts' => -1,
          'post_type' => $types,
          'meta_query' => array (
            array (
              'key' => '_user_liked',
              'value' => $user->ID,
              'compare' => 'LIKE'
            )
          ) );      
        $sep = '';
        $like_query = new WP_Query( $args );
        if ( $like_query->have_posts() ) : ?>
        <p>
        <?php while ( $like_query->have_posts() ) : $like_query->the_post(); 
        echo $sep; ?><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
        <?php
        $sep = ' &middot; ';
        endwhile; 
        ?>
        </p>
        <?php else : ?>
        <p><?php _e( 'You do not like anything yet.', 'YourThemeTextDomain' ); ?></p>
        <?php 
        endif; 
        wp_reset_postdata(); 
        ?>
        </td>
    </tr>
</table>

0 个答案:

没有答案