Reppiks
Forum Replies Created
-
I have come up with a solution and am sharing in case anybody else would like to use it. Thanks again Alimir, what you provided before lead me in a great direction. I am a novice in PHP and never learned SQL so this journey has been quite the learning experience.
Sort post/media by total like count for the previous month:
First, I set up args for the begin time and the end time I want to query for.The code below set’s current timezone for dates to be based off of. (I’m in Memphis so mine is America/Chicago…replace with yours) Otherwise it would use the timezone of the server that’s hosting the page.
date_default_timezone_set('America/Chicago');
I set up the start and end times like this because having the way that was suggested above would not actually count the days of the month but base the days off the current month. I also chose this date format because it was how the time_date was displayed in the database table.
$start = date('Y-m-d 00:00:00', strtotime("first day of -1 month")); // First day of the month $end = date('Y-m-d 23:59:59', strtotime("last day of -1 month")); // 't' gets the last day of the month
The info we needed I believe is beyond the scope of wp_query. (Because I needed to access the _ulike table and columns) So I used $qpdb to do a query directly to the database. Through a lot of trial and error this is what I came up with this:
global $wpdb; $like_counts = $wpdb->get_results( " SELECT post_id, COUNT(post_id) as like_number, status FROM {$wpdb->prefix}ulike WHERE {$wpdb->prefix}ulike.date_time >= '$start' AND {$wpdb->prefix}ulike.date_time <= '$end' AND {$wpdb->prefix}ulike.status = 'like' GROUP BY {$wpdb->prefix}ulike.post_id ORDER BY COUNT(post_id) DESC "); foreach ($like_counts as $like_count)
That query counts how many times a post occur in the query between the dates above and groups them by the post id.
I then did a MPP_Media_Query (which is similar to WP_Query) so that it would only pull uploaded media instead of media and post, and set id = $like_count->post_id as the only argument for it.
- This reply was modified 7 years, 6 months ago by Reppiks.
Thanks for the awesome feedback. That would be a neat feature if you guys get a chance to figure it out. Wish you the best of luck in that endeavor. I figured it was a stretch for it to be a simple solution. You went above and beyond with the tip for adding the message. Will try it out once I get a bit of sleep.
Thanks again for your help,
Cheers!Forum: Plugins
In reply to: [WP ULike - All-in-One Engagement Toolkit] Remove Like on certain pagesPlease don’t mark these as resolved without receiving feedback. This would work for regular setups. Unfortunately I’m trying to do what was suggested here:https://buddydev.com/mediapress-development/mediapress-like-unlike-button-for-photos-videos-etc-with-wp-ulike-plugin/
That gives me the ability for my users to like media uploaded by mediapress. I will look into the template files for mediapress when I get a chance to and see if I can add the php
<?php if(function_exists('wp_ulike')) wp_ulike('get'); ?>
to it and hope it all still works. I will let you know the status but your post did not solve this issue in my unique scenario.It seems “pages” have to be ticked for it to be displayed on the media lightbox and attachment page.
- This reply was modified 7 years, 6 months ago by Reppiks.
This issue is not resolved by the way! Not sure how that happened, is there a way you can un-resolve it Alimir?Ok the status is set back right.
- This reply was modified 7 years, 6 months ago by Reppiks.
Hello agian @alimir
The code you gave isn’t working for me. The query doesn’t seem to respond to the date. At least not in that format. Here is what I got going right now.
I wanted to get the previous months and the follow format is the only way that works and keeps the right amount of days for the month. Using your code and providing the month produced results where the month would be right but the first and last days would be based on the current month.
date_default_timezone_set('America/Chicago'); <?php $start = date('Y.n.d', strtotime("first day of -1 month")); // First day of the month $end = date('Y.n.d', strtotime("last day of -1 month")); // 't' gets the last day of the month $args = array( 'meta_key' => '_liked', 'gmeta_query' => array( array( 'key' => '_liked', 'value' => array($start, $end), 'compare' => 'BETWEEN', 'type' => 'DATE' ) ) ); // 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(); ?> <p text-align="center"> <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></p> <p>Number of Likes: <?php if (function_exists('wp_ulike_get_post_likes')): echo wp_ulike_get_post_likes(get_the_ID()); endif; ?></p> <?php echo '<a href="'.get_permalink($get_ulike_log->post_id).'" title="'.get_the_title($get_ulike_log->post_id).'">'.get_the_title($get_ulike_log->post_id).'</a>'; ?>>
I also tried to setup a similar code to just bring up post and not mediapress content in case that was the problem, and still got the same results. (Using regular wp_query and meta_query) No matter what date is given it just shows all post that have likes.
Forum: Plugins
In reply to: [Like Button Rating ? LikeBtn] How would I track like statistics by month?Hello again,
Thanks for your help. I’m currently using MediaPress and was referring to images upload through it. sorry I wasn’t clear on that at first. (New to buddypress and didn’t know how media press worked) I noticed in the setting you can have likes for mpp-gallery, (which doesn’t show for me, nor on profiles but I don’t need these features) but not any specific mpp-media.
I would like for my users to be able to like the actual uploaded content and keep track of it’s statistics.
I basically want something similar to this:
https://buddydev.com/mediapress-development/mediapress-like-unlike-button-for-photos-videos-etc-with-wp-ulike-plugin/They are able to add a like button inside the lightbox as well as on the MediaPress attachment page.
Forum: Plugins
In reply to: [WP ULike - All-in-One Engagement Toolkit] Is the WP ULike website down?Yea me too. This plugin is working out quite well for my site and I would hate to have to replace it. I’ve have noticed they haven’t been active in this support forums for almost 2 months…about the same time as their last update.
Let us keep our fingers crossed.
Forum: Plugins
In reply to: [WP ULike - All-in-One Engagement Toolkit] Is the WP ULike website down?Seems to be back up. I was having the same problem and now am not. Not much on the site though.
Forum: Plugins
In reply to: [MediaPress] Query post created by mediapressYES!!!! 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::: Update :::
So I almost have it 100% figured out. I know how to get the most liked media to show. I needed to use mpp_media_query instead of wp_query and use some of the properties and methods that were added by MediaPress.
Here is what my working code looks like:
<?php $args = array( //'monthnum' => 1, '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(); ?> <p text-align="center"> <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></p> <?php } } else { // no posts found } /* Restore original media data */ mpp_reset_media_data(); ?>
The main problem! For post, media, etc.
This still just list most liked with no date range option. So it will show the most liked media period, from all time.
I still need to know how to set a time range for the query. Putting the monthnum argument in (like I did in my previous post) doesn’t list the post by the date they were liked, but by when they were published.WP Ulike tracks the time and date of likes in the statistics. How would I get this data for use in a query of post?
(Example: Query post with meta-key = _liked from Jan to Feb)::: Update :::
So I now know what to add to the above code to get the results for the previous month.
I just need to add something like this to the array:
'monthnum' => 4,
Right now I don’t mind manually changing the month number every month and I should be able to write up something that can fetch the current month – 1 to have it auto updated. (Will be some PHP practice for me, but if somebody wants to share a script that’ll do it I’m not against it.)
What I am still stuck at is having the info bring up “posts” made by MediaPress. I am using WP ULike with MediaPress content following the tutorial on this page: https://buddydev.com/mediapress-development/mediapress-like-unlike-button-for-photos-videos-etc-with-wp-ulike-plugin/
WP ULink tracks the likes just fine and I can even see the post_id and the attachment page of the media in the stats of WP ULike. My problem is that wordpress doesn’t treat the Mediapress post as any type of post_type, (or at least I don’t know whay type) so the above code only works for post, pages, etc but not MediaPress post. (Even when post_type is set to any)
I believe the solution for me will lie in how WP Ulike gets it’s stats info. It is able to track a post_id as well as attachment page so there must be a way this info is queried by the plug-in. Again I am no PHP programmer and can only read it a bit so digging out what I need from the plug-in’s editable files is proving difficult. How does WP ULike get it’s stats?
Forum: Themes and Templates
In reply to: [Responsive] Can’t Center GalleriesThanks AddWeb! Yes that seems to do the trick. It was a lot of help. I forgot all about being able to use percentages now. I was tryiing pretty much that same code with “max-width” set but it wasn’t that responsive.
How did you come up with 72%!!? Anything more or less breaks the centering smh.
Forum: Themes and Templates
In reply to: [Twenty Seventeen] Can’t Center GalleryI have started another thread here: https://www.ads-software.com/support/topic/cant-center-galleries/
I am linking this in case someone in the future comes here needing the same solution, they can see if any good answers come from the new thread that may help them.
Forum: Themes and Templates
In reply to: [Twenty Seventeen] Can’t Center GalleryI realized I posted this for the wrong theme. The galleries are working fine under the 2017 theme. (I’m working on a few sites so I got it confused.) The theme I am having problems with is “Responsive”. They have a new update so I will try that first and if I am still having problems I will make a post under the correct theme.
Forum: Themes and Templates
In reply to: [Twenty Seventeen] Can’t Center GallerySorry about that Poonam, it should be working now. This is an older site I’m updating and forgot I had a country block on there. I use to get A LOT of spam and attacks from other countries.