This topic has 6 replies, 2 voices, and was last updated 9 years by sharmstr.

  • Author
  • #80842
     costa974
    Participant

    I have a custom post type “painting” and it is user generated.

    Then a menu “My paintings”

    How can I display only the posts/paintings of the current logged user?

    Thanks

    #80849
     sharmstr
    Moderator

    You should read this: http://www.wpbeginner.com/wp-tutorials/how-to-create-custom-post-types-in-wordpress/ Especially the Querying Custom Post Types section. Then you can read this for all the arguments you can pass to wp_query https://codex.wordpress.org/Class_Reference/WP_Query

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #80850
     sharmstr
    Moderator

    Sorry, hit submit too soon. Finally, read this to get the current user id https://codex.wordpress.org/Function_Reference/get_current_user_id

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #80854
     costa974
    Participant

    I see… but can I do it with the Visual Composer or I have to code something?
    Don’t you have an example?
    Thanks

    #80855
     sharmstr
    Moderator

    You cant do it with VC. You need to code it. Examples are in the links I gave you. Its all wordpress stuff and not Kleo specific.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #80986
     costa974
    Participant

    add_shortcode(‘pitturo_my_gallery’, ‘pitturo_my_gallery_shortcode’);

    function pitturo_my_gallery_shortcode() {

    $args = array(
    ‘post_type’ => ‘painting’,
    ‘post_status’ => ‘publish’,
    ‘author’ => get_current_user_id()
    );

    $query = new WP_Query($args);
    if ($query->have_posts()) {
    while ($query->have_posts()) {
    $query->the_post();
    get_template_part(‘page-parts/post-content-masonry’);
    }
    }

    wp_reset_query();
    }

    it works, but the layout is broken… ho can I reuse the kleo masonsry template?

    #81022
     sharmstr
    Moderator

    You havent add the masonry divs so it has no idea what to do

    COPY CODE
    
    if ($query->have_posts()) {
    	echo '<div class="posts-listing responsive-cols kleo-masonry per-row-3 with-meta masonry-listing">';
    	while ($query->have_posts()) {
    		$query->the_post();
    		get_template_part('page-parts/post-content-masonry');
    	}
    	echo '</div>';
    }
    
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

Viewing 7 posts - 1 through 7 (of 7 total)

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?