udniweca
Forum Replies Created
-
Forum: Plugins
In reply to: [Advanced Queries] Post by view count + elementorHellow,
I updated to 1.0.9 and the problem remains. If i enter “views” as the dynamic “order by field” i get only one post displayed, and if i write “post_views” instead i get nothing (while the elementor widget is set to display up to 6 posts’ thumbnails).
I got it to work for a moment by entering “pvc_most_viewed_posts” as a query ID, but after re-installing my plugins i can’t get it to work anymore. So i’m back at square one. Thank you for the support, if you have any ideas on how to display posts by “views” i’m all ears 🙂 .
Kind regards,
Forum: Plugins
In reply to: [Advanced Queries] Post by view count + elementorI’ll show you what it does on my interface :
Elementor Post Widget => set to show 6 posts per page => dynamic order by field “views” => only one result. Screenshot here
Elementor Post Widget => set to show 6 posts per page => dynamic order by field “post_views” => no results. Screenshot here
Forum: Plugins
In reply to: [Advanced Queries] Post by view count + elementorHellow,
Thank you so much for your answer. Well when i cheked for the custom meta fields in the post panel, i didn’t find anything, there is only a data in the settings bar on the right but it doesn’t show a meta field that i can clearly use. Here is a screenshot .
So i went into the “query” file of the plugin “Post View Counter” , and it seems that the meta field would be ” post_views ” . But when i enter ” post_views ” in the Dynamic OrderBy Field of advanced query in the elementor post widget, it becomes empty. My only way to display something is to write ” views ” but then it only display one post.
I’m kind of desperate here. I’ll paste you the query file of the plugin Post Views Counter in case it helps :
<?php
// exit if accessed directly
if ( ! defined( ‘ABSPATH’ ) )
exit;/**
* Post_Views_Counter_Query class.
*
* @class Post_Views_Counter_Query
*/
class Post_Views_Counter_Query {public function __construct() {
// actions
add_action( ‘pre_get_posts’, array( $this, ‘extend_pre_query’ ), 1 );// filters
add_filter( ‘query_vars’, array( $this, ‘query_vars’ ) );
add_filter( ‘posts_join’, array( $this, ‘posts_join’ ), 10, 2 );
add_filter( ‘posts_groupby’, array( $this, ‘posts_groupby’ ), 10, 2 );
add_filter( ‘posts_orderby’, array( $this, ‘posts_orderby’ ), 10, 2 );
add_filter( ‘posts_fields’, array( $this, ‘posts_fields’ ), 10, 2 );
add_filter( ‘the_posts’, array( $this, ‘the_posts’ ), 10, 2 );
}/**
* Register views_query var.
*
* @param array $query_vars
* @return array
*/
public function query_vars( $query_vars ) {
$query_vars[] = ‘views_query’;return $query_vars;
}/**
* Extend query with post_views orderby parameter.
*
* @param object $query
*/
public function extend_pre_query( $query ) {
if ( isset( $query->query_vars[‘orderby’] ) && $query->query_vars[‘orderby’] === ‘post_views’ )
$query->pvc_orderby = true;
}/**
* Modify the db query to use post_views parameter.
*
* @global object $wpdb
* @param string $join
* @param object $query
* @return string
*/
public function posts_join( $join, $query ) {
$sql = ”;if ( ! empty( $query->query[‘views_query’] ) ) {
if ( isset( $query->query[‘views_query’][‘year’] ) )
$year = (int) $query->query[‘views_query’][‘year’];if ( isset( $query->query[‘views_query’][‘month’] ) )
$month = (int) $query->query[‘views_query’][‘month’];if ( isset( $query->query[‘views_query’][‘week’] ) )
$week = (int) $query->query[‘views_query’][‘week’];if ( isset( $query->query[‘views_query’][‘day’] ) )
$day = (int) $query->query[‘views_query’][‘day’];// year
if ( isset( $year ) ) {
// year, week
if ( isset( $week ) && $this->is_valid_date( ‘yw’, $year, 0, 0, $week ) ) {
$sql = ” AND pvc.type = 1 AND pvc.period = ‘” . str_pad( $year, 4, 0, STR_PAD_LEFT ) . str_pad( $week, 2, 0, STR_PAD_LEFT ) . “‘”;
// year, month
} elseif ( isset( $month ) ) {
// year, month, day
if ( isset( $day ) && $this->is_valid_date( ‘ymd’, $year, $month, $day ) ) {
$sql = ” AND pvc.type = 0 AND pvc.period = ‘” . str_pad( $year, 4, 0, STR_PAD_LEFT ) . str_pad( $month, 2, 0, STR_PAD_LEFT ) . str_pad( $day, 2, 0, STR_PAD_LEFT ) . “‘”;
// year, month
} elseif ( $this->is_valid_date( ‘ym’, $year, $month ) ) {
$sql = ” AND pvc.type = 2 AND pvc.period = ‘” . str_pad( $year, 4, 0, STR_PAD_LEFT ) . str_pad( $month, 2, 0, STR_PAD_LEFT ) . “‘”;
}
// year
} elseif ( $this->is_valid_date( ‘y’, $year ) ) {
$sql = ” AND pvc.type = 3 AND pvc.period = ‘” . str_pad( $year, 4, 0, STR_PAD_LEFT ) . “‘”;
}
// month
} elseif ( isset( $month ) ) {
// month, day
if ( isset( $day ) && $this->is_valid_date( ‘md’, 0, $month, $day ) ) {
$sql = ” AND pvc.type = 0 AND RIGHT( pvc.period, 4 ) = ‘” . str_pad( $month, 2, 0, STR_PAD_LEFT ) . str_pad( $day, 2, 0, STR_PAD_LEFT ) . “‘”;
// month
} elseif ( $this->is_valid_date( ‘m’, 0, $month ) ) {
$sql = ” AND pvc.type = 2 AND RIGHT( pvc.period, 2 ) = ‘” . str_pad( $month, 2, 0, STR_PAD_LEFT ) . “‘”;
}
// week
} elseif ( isset( $week ) && $this->is_valid_date( ‘w’, 0, 0, 0, $week ) ) {
$sql = ” AND pvc.type = 1 AND RIGHT( pvc.period, 2 ) = ‘” . str_pad( $week, 2, 0, STR_PAD_LEFT ) . “‘”;
// day
} elseif ( isset( $day ) && $this->is_valid_date( ‘d’, 0, 0, $day ) ) {
$sql = ” AND pvc.type = 0 AND RIGHT( pvc.period, 2 ) = ‘” . str_pad( $day, 2, 0, STR_PAD_LEFT ) . “‘”;
}if ( $sql !== ” )
$query->pvc_query = true;
}// is it sorted by post views?
if ( ( $sql === ” && isset( $query->pvc_orderby ) && $query->pvc_orderby ) || apply_filters( ‘pvc_extend_post_object’, false, $query ) === true )
$sql = ‘ AND pvc.type = 4’;// add date range
if ( $sql !== ” ) {
global $wpdb;$join .= ” LEFT JOIN ” . $wpdb->prefix . “post_views pvc ON pvc.id = ” . $wpdb->prefix . “posts.ID” . $sql;
}return $join;
}/**
* Group posts using the post ID.
*
* @global object $wpdb
* @param string $groupby
* @param object $query
* @return string
*/
public function posts_groupby( $groupby, $query ) {
// is it sorted by post views or views_query is used?
if ( ( isset( $query->pvc_orderby ) && $query->pvc_orderby ) || ( isset( $query->pvc_query ) && $query->pvc_query ) || apply_filters( ‘pvc_extend_post_object’, false, $query ) === true ) {
global $wpdb;$groupby = trim( $groupby );
if ( strpos( $groupby, $wpdb->prefix . ‘posts.ID’ ) === false )
$groupby = ( $groupby !== ” ? $groupby . ‘, ‘ : ”) . $wpdb->prefix . ‘posts.ID’;if ( ! isset( $query->query[‘views_query’][‘hide_empty’] ) || $query->query[‘views_query’][‘hide_empty’] === true )
$groupby .= ‘ HAVING post_views > 0’;
}return $groupby;
}/**
* Order posts by post views.
*
* @global object $wpdb
* @param string $orderby
* @param object $query
* @return string
*/
public function posts_orderby( $orderby, $query ) {
// is it sorted by post views?
if ( ( isset( $query->pvc_orderby ) && $query->pvc_orderby ) ) {
global $wpdb;$order = $query->get( ‘order’ );
$orderby = ( ! isset( $query->query[‘views_query’][‘hide_empty’] ) || $query->query[‘views_query’][‘hide_empty’] === true ? ‘post_views’ : ‘pvc.count’ ) . ‘ ‘ . $order . ‘, ‘ . $wpdb->prefix . ‘posts.ID ‘ . $order;
}return $orderby;
}/**
* Return post views in queried post objects.
*
* @param string $fields
* @param object $query
* @return string
*/
public function posts_fields( $fields, $query ) {
if ( ( ! isset( $query->query[‘fields’] ) || $query->query[‘fields’] === ” ) && ( ( isset( $query->pvc_orderby ) && $query->pvc_orderby ) || ( isset( $query->pvc_query ) && $query->pvc_query ) || apply_filters( ‘pvc_extend_post_object’, false, $query ) === true ) )
$fields = $fields . ‘, SUM( IFNULL( pvc.count, 0 ) ) AS post_views’;return $fields;
}/**
* Extend query object with total post views.
*
* @param array $posts
* @param object $query
* @return array
*/
public function the_posts( $posts, $query ) {
if ( ( isset( $query->pvc_orderby ) && $query->pvc_orderby ) || ( isset( $query->pvc_query ) && $query->pvc_query ) || apply_filters( ‘pvc_extend_post_object’, false, $query ) === true ) {
$sum = 0;// any posts found?
if ( ! empty( $posts ) ) {
foreach ( $posts as $post ) {
if ( ! empty( $post->post_views ) )
$sum += (int) $post->post_views;
}
}// pass total views
$query->total_views = $sum;
}return $posts;
}/**
* Validate date helper function.
*
* @param string $type
* @param int $year
* @param int $month
* @param int $day
* @param int $week
* @return bool
*/
private function is_valid_date( $type, $year = 0, $month = 0, $day = 0, $week = 0 ) {
switch ( $type ) {
case ‘y’:
$bool = ( $year >= 1 && $year <= 32767 );
break;case ‘yw’:
$bool = ( $year >= 1 && $year <= 32767 && $week >= 0 && $week <= 53 );
break;case ‘ym’:
$bool = ( $year >= 1 && $year <= 32767 && $month >= 1 && $month <= 12 );
break;case ‘ymd’:
$bool = checkdate( $month, $day, $year );
break;case ‘m’:
$bool = ( $month >= 1 && $month <= 12 );
break;case ‘md’:
$bool = ( $month >= 1 && $month <= 12 && $day >= 1 && $day <= 31 );
break;case ‘w’:
$bool = ( $week >= 0 && $week <= 53 );
break;case ‘d’:
$bool = ( $day >= 1 && $day <= 31 );
break;
}return $bool;
}}
- This reply was modified 6 years, 2 months ago by udniweca.
Forum: Themes and Templates
In reply to: [Neve] Neve + Elementor : single page content not showingOk… well i haven’t found any solutions, and there is nothing in any error log. So the workaround i found is to use the plugin Jonradio Multiple Themes, to use Neve for my pages, and another theme for my single posts.
It will work for me, i hope that no one will be stuck with a display probleme with Neve, having trouble showing single posts’ content when in boxed content diplay, while using an elementor custom template for their post.
Thanks anyways and good luck to anyone who comes by here with the same problem.
Forum: Themes and Templates
In reply to: [Neve] Neve + Elementor : single page content not showingThe closest thing that i found about what could possibly solve my problem was this thread : https://wordpress.org/support/topic/neve-single-post-layout-and-elementor/ .
But my problem is not “my homemade template doesn’t display when i choose the default layout”…. no my template shows… however the “post content” block/widget from elementor, that allows me to display the video, doesn’t show it’s content on Neve when the page is in “default display”.
Thank you in advance for anyone who is brave enought to give it a look 🙂