• Resolved Reppiks

    (@reppiks)


    Hello, I would like to query post created by mediapress. (The upload attachment pages) The problem is wordpress doesn’t treat them as regular post and therefore I do not know the “post_type” or if it’s a post type at all.

    What I want to do with this info is track the likes of uploaded images. I am using the setup found here: https://buddydev.com/mediapress-development/mediapress-like-unlike-button-for-photos-videos-etc-with-wp-ulike-plugin/

    Everything works fine as far as being liked and within WP Ulike statistics I can see the post-id of the uploads that receive likes. That tells me that some type of post is generated when things are uploaded.

    I want ot use code like this one:

    <?php
        $args = array(
            'monthnum' => 4,
            'meta_key' => '_liked',
            'orderby' => 'meta_value_num',
        );
    
        $post_query = new WP_Query($args);
    if($post_query->have_posts() ) {
      while($post_query->have_posts() ) {
        $post_query->the_post();
        ?>
        <h2><?php the_title(); ?></h2>
        <?php
      }
    }
    ?>

    This code shows the top post for the previous month. The above code works fine for regular post but I would like to know how I would set that up to query the attachment post made by mediapress. (specifically photos) Is that possible?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author BuddyDev

    (@buddydev)

    Hi,
    Thank you for posting.

    I am not sure what are you looking for here but here is how we do the media query

    https://buddydev.com/mediapress/topics/api-reference/core/mpp_media_query/

    We use a meta key ‘_is_mpp_media’ to mark a media as belonging to the MediaPress.

    If you use WP_Query, It won’t honour the privacy.

    References:-
    https://buddydev.com/mediapress/topics/api-reference/core/mpp_media_query/
    https://buddydev.com/mediapress/topics/api-guides/mediapress-media-loop/

    Hope that helps.

    Regards
    Brajesh
    BuddyDev Team

    Thread Starter Reppiks

    (@reppiks)

    YES!!!! This did help, thank you so much. I read all through those refs you gave me before today but it just didn’t click then lol. I have a working solution for displaying the most liked media.
    I just now need to figure out how to list them by the date they were liked. But that I’m sure is something that I will have to figure with the other plug-in’s devs because that part doesn’t relate to MediaPress but WP ULike.

    I will post my code in case others are looking for a similar solution.

    <?php
        $args = array(
            'meta_key' => '_liked',
            'orderby' => 'meta_value_num',
    
        );
    
    // The Query
    	$the_media_query = new MPP_Media_Query( $args );
     
    // The Loop
    if ( $the_media_query->have_media() ) {
    
        while ( $the_media_query->have_media() ) {
            $the_media_query->the_media();
    	?>
    		<a href="<?php mpp_media_permalink() ;?>" <?php mpp_media_html_attributes( array( 'class' => 'mpp-item-thumbnail mpp-media-thumbnail mpp-photo-thumbnail' ) ); ?>>
            	<img class="aligncenter" src="<?php mpp_media_src( 'thumbnail' ) ;?>" alt="<?php echo esc_attr( mpp_get_media_title() );?> "/>
    		</a>
            
            <?php
        }
    
    } else {
        // no posts found
    }
    /* Restore original media data */
    mpp_reset_media_data();
    ?>

    Thanks again for your help!
    Cheers

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query post created by mediapress’ is closed to new replies.