How to make in WordPress admin panel sortable column for the custom field, that count the number of page impressions?

Good day! I try to make display post counter for WordPress. Output count of views function getPostViews($postID){ $count_key = ‘post_views_count’; $count = get_post_meta($postID, $count_key, true); if($count==”){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, ‘0’); return “0”; } return $count.”;} register view function setPostViews($postID) { $count_key = ‘post_views_count’; $count = get_post_meta($postID, $count_key, true); if($count==”){ $count = 0; delete_post_meta($postID, $count_key); … Read more

Custom taxonomy list and sortby letter pagination problem

I’m getting a taxonomy list page with pagination using this code : <?php $sortby = $_GET[‘sortby’]; if(isset($_GET[‘showall’])): $args = array(‘hide_empty’ => 0); else: $page = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $per_page = 1; //number of actores to show per page $offset = ($page-1) * $per_page; $args = array(‘number’ => $per_page, ‘offset’ => $offset, ‘hide_empty’ => … Read more

How to sort posts with the first 2 or 3 by latest, and the rest is random?

I’m trying to sort my posts in the way I stated in the title. What’s the simplest way to do this? I know how to change the order by object using the pre_get_post hook. But how can I use it to get what I need? EDIT: here’s my code so far add_action(‘pre_get_posts’, ‘filter_category_orderby’); function filter_category_orderby($query){ … Read more

Meta query with order by another custom field

Edit: I will try to explain in detail my problem. I am working on a portfolio site. There are a few custom post types: Projects, Publications, Exhibitions, Lectures and Slides. Home page consists of following sections: slider with Slides portfolio consisting of: selected (marked by Client) Projects, Publications, Exhibitions and Lectures and remaining Projects, Publications, … Read more

Why anything done on comments_array hook gets reset?

I am writing a plugin that will allow simple comment upvoting. I am trying to sort comments by the number of upvotes. But anything I do on the comments_array Hook gets somehow reset. My question is where and how? Here is my code: add_filter( ‘comments_array’, ‘biiird_order_comments_by_likes’ ); function biiird_order_comments_by_likes( $array ) { $arraya = $array; … Read more