Custom Content Type Manager
[resolved] Display only logged in user's posts (5 posts)

  1. miketurco
    Posted 3 years ago #

    I am trying to use the summarize-posts shortcode with the filter post_author="x", where x is the user id of the logged in user.

    In other words, if Jack and Jane are logged in users, I only want Jack to see his posts, and Jane should only see her posts.

    Is there a way to do this?




  2. fireproofsocks
    Plugin Contributor

    Posted 3 years ago #

    You could do that, but not with the shortcode. You'd need to use some PHP functions to get the id of the currently logged in user, and then pass that id as an argument to the GetPostsQuery::get_posts function. The shortcode can't compete with PHP for functionality and customizations.

  3. miketurco
    Posted 3 years ago #

    I'm in the midst of things and have it working, and am still doing cleanup work. I'm on the steep end of the learning curve of the whold wp/php/query/template thing. So, swallow your coffee and set down your cup. Here is where I'm at with a template right now, which is a hack of stuff you've provided + a file from my theme + whatever else I've found online that makes sense:

    Like I said, I'm still cleaning things up, but this code does display a list of custom posts generated by the individual who is logged in.

    // Exit if accessed directly
    if ( !defined('ABSPATH')) exit;
     * Blog Template
       Template Name: Cards list all
     * @file           cards-list-all.php
     * @package        Responsive
     * @author         Emil Uzelac
     * @copyright      2003 - 2012 ThemeID
     * @license        license.txt
     * @version        Release: 1.0
     * @filesource     wp-content/themes/responsive/blog.php
     * @link           http://codex.wordpress.org/Templates
     * @since          available since Release 1.0
    <?php get_header(); ?>
    <?php global $more; $more = 0; ?>
    <!--        <div id="content-blog" class="grid col-620"> -->
        if ( get_query_var('paged') )
    	    $paged = get_query_var('paged');
    	elseif ( get_query_var('page') )
    	    $paged = get_query_var('page');
    		$paged = 1;
     <?php query_posts( 'post_type=cards'); ?>
    <?php if (have_posts()) : ?>
    $theuser = get_current_user_id();
    echo ($theuser);
    		<?php while (have_posts()) : the_post(); ?>
    <?php  $theauthor = get_the_author_meta('id');  ?>
    <?php if ($theauthor == $theuser ) : ?>
    <tr><td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td><td><?php print_custom_field('tagC'); ?></td><td><?php print_custom_field('typeC'); ?></td><td><?php echo($theauthor); ?></td></tr>
    <?php endif; ?>
            <?php endwhile; ?> 
            <?php if (  $wp_query->max_num_pages > 1 ) : ?>
            <div class="navigation">
    			<div class="previous"><?php next_posts_link( __( '‹ Older posts', 'responsive' ) ); ?></div>
                <div class="next"><?php previous_posts_link( __( 'Newer posts ›', 'responsive' ) ); ?></div>
    		</div><!-- end of .navigation -->
            <?php endif; ?>
    	    <?php else : ?>
            <h1 class="title-404"><?php _e('404 — Fancy meeting you here!', 'responsive'); ?></h1>
            <p><?php _e('Don't panic, we'll get through this together. Let's explore our options here.', 'responsive'); ?></p>
            <h6><?php _e( 'You can return', 'responsive' ); ?> <a href="<?php echo home_url(); ?>/" title="<?php esc_attr_e( 'Home', 'responsive' ); ?>"><?php _e( '&larr; Home', 'responsive' ); ?></a> <?php _e( 'or search for the page you were looking for', 'responsive' ); ?></h6>
            <?php get_search_form(); ?>
    <?php endif; ?>
              </div><!-- end of #content-blog -->
    <?php wp_reset_query() ?>
    <?php get_footer(); ?>
  4. miketurco
    Posted 3 years ago #

    And thanks, again, for your Awesome plugin and for all your help.

  5. fireproofsocks
    Plugin Contributor

    Posted 3 years ago #

    Glad you found a solution!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic


No tags yet.