在页面上仅显示已登录用户(Wordpress-PHP)的帖子

时间:2018-07-29 17:18:40

标签: php wordpress

对于我在Wordpress中的网站,我需要创建一个页面,用户可以在该页面上看到他们在网络上上传的内容(视频,评论,事件等),但是在此页面中仅显示以下信息:他们已经上传,而不是其他用户的上传。也就是说,我需要键入代码,以便仅显示由登录用户生成的信息。我做了很多尝试,但是我知道我无法正确地得出代码的最后一部分,并且我必须添加行代码以显示正确的结果:

  1. 使用 echo return 这样做是否正确?这行代码应该如何?我做了很多尝试,但没有成功(请参见下面的代码)。

  2. 我是否必须在代码中使用 函数 add_filter 命令?

  3. 如果您可以看下面的代码。供您参考,以下是此代码的输出: Array

  4. 在下面,我列出了一些我一直在搜索的有关此主题的链接:

https://codex.wordpress.org/Class_Reference/WP_Query#Code_Documentation https://codex.wordpress.org/Function_Reference/get_posts https://wordpress.stackexchange.com/questions/69614/logged-in-user-id-as-post-id Get post ID of current logged in user and add a link to the menu

代码:

<?php // Accedemos a la variable global
global $current_user;
// Obtenemos la informacion del usuario conectado y asignamos los valores a 
las variables globales
get_currentuserinfo();
// Guardamos el nombre del usuario en una variable
$usuario = esc_attr($current_user->user_login);
$args = array(
'author'        =>  $current_user->ID, 
'orderby'       =>  'post_date',
'order'         =>  'ASC',
'posts_per_page' => -1 // no limit
);
$current_user_posts = get_posts( $args );
echo $args;
?>

谢谢

0 个答案:

没有答案