Tagged: ,

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1267749

    Hi, I have a couple of pages where I display custom post types. The post types in the two pages are the same, but they are differentiated by a custom function that works on a acf field (in this case a number corresponding to “year”), showed herebelow:

    add_filter('avia_post_slide_query', 'avia_post_slide_query_mod',10, 2);
    function avia_post_slide_query_mod($query, $params) {
    	$posts = get_posts($query);
    	$today_year = date('yy');
    	$two_years_ago = $today_year - 2;
    	$current = array();
    
    		foreach( $posts as $post ) {
    			$meta = get_post_meta($post->ID);
    			
    			
    			if (is_page(112)){
    				$acf_year = $meta['anno'][0];
    				if($acf_year >= $two_years_ago & $acf_year <= $today_year) {
    				$current[] = $post->ID;
    				}	
    
    			}
    			else if (is_page(204))	{
    				$acf_year = $meta['anno'][0];
    				if($acf_year < $two_years_ago) {
    				$current[] = $post->ID;
    				}	
    			}
    			else if (is_archive()) {
    				return $query;
    			}
    		}
    
    	$query['post__in'] = $current;
    
    	return $query;
    }
    

    What I need is to add the possibility (in front-end) to add a orderby option, similar to the one that is suggested in the back-end blog post (see Enfold documentation)

    My need is to enable the possibility of sorting posts by the following parameters: year (= acf field); location (=acf field); post title

    I tried to use an external plugin (Search&Filter), but it doesn’t work well as it searches among all posts created (hence also those that are not listed in the page).

    Can you suggest me how to solve the problem?

    #1270089

    Hey Elena,

    Thank you for the inquiry

    This is possible but it will require modifications that are beyond the scope of support. You may need to hire a freelance developer or contact our partner, Codeable.

    If you want to implement it yourself, you could look into the following articles for reference.

    // https://rudrastyh.com/wordpress/ajax-post-filters.html
    // http://techslides.com/sort-wordpress-posts-by-modified-date-using-a-url-param

    The second solution is probably much more simple because the sorting is based on the query or URL parameters, compare to the first solution which requires AJAX and template modifications.

    Best regards,
    Ismael

    #1270133

    Thanks Ismael, I will check the two articles you mentioned!

    #1270321

    Hi,

    Please let us know if you need additional help, or shall we close this topic?

    Best regards,
    Jordan Shannon

    #1270899

    Yes please close the topic!

    #1271058

    Hi,

    Thanks for the update, I’ll go ahead and close this thread for now then. Please open a new thread if you should have any further questions or problems.

    Best regards,
    Rikard

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘How to add an order/orderby option on blog post front-end side’ is closed to new replies.