• hello ;
    i need help plz
    i want to create a page containing the addresses and links of post for the user online now(is login), by Category
    For example
    page : post user online
    Category 1
    xxxxx – xxxxxx
    xxxxxx xxxxxx

    Category 2
    yyyyy yyyyyyy
    yyyyy yyyyyyy

    (xxxxx,yyyyy is the post of user online now)

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Create a custom page template that does the following:
    Get the current user’s ID with get_current_user_id().
    Use a new WP_Query object to get all posts authored by the current user ID, ordered by category.
    Run the standard “Loop” on the returned posts.
    In order to know which category header to output, and when to output it, check the categories of each post with wp_get_post_categories().
    When the loop is done use wp_reset_postdata().

    There is one complication preventing this from being fairly straight forward. You can’t use WP_Query alone to order by category. To order by category, hook into the filters ‘posts_join_paged’ and ‘posts_orderby’ and alter the query parameters to get the results ordered by category. This part of the code would go in your theme’s (or better yet, your child theme’s) functions.php file.

    Once all that is taken care of, add a new page and specify to use your custom template. You only need to assign a title to define the permalink used to access the page. You do not need any content unless you’ve set up the template to use content.

Viewing 1 replies (of 1 total)
  • The topic ‘how i can create page – post of user login (online now)’ is closed to new replies.