Viewing 17 posts - 1 through 17 (of 17 total)
  • Author
    Posts
  • #348003

    Hello,

    I try to use the Enfold theme for a real estate website. I would like to sort the entries (portfolio) in order of price from highest to lowest. For this I try to use the excerpt because custom fields are not available with portfolio post type. (Unless I’m mistaken?)

    My questions are:

    – How do I proceed? (add php code to functions.php?, create template page?)
    – How to prevent updates replace my configurations? (Child theme?)
    – Should I use another method instead?
    – Should I rather use an extension of a real estate broker?
    – If so, do you know some good real estate plugins which are compatible with the Enfold theme ?
    – Do you have any other suggestions for my purposes?

    (If you are a member of Kriesi team, is it possible to know whether you will eventually add such features in future updates?)

    A big thank you in advance.

    #348286

    Hey!

    You’d need to use two snippets in functions.php, (child theme would be ideal):

    The first one would be to enable custom fields for Portfolio items:

    add_filter('avf_portfolio_cpt_args', 'avf_portfolio_add_custom_fields', 1);
    function avf_portfolio_add_custom_fields($args) {
    	$args['supports'] = array('title','thumbnail','excerpt','editor','comments', 'custom-fields');
    	return $args;
    }

    And the second one to alter the portfolio grid order (“custom_price” being the custom field):

    function custom_post_grid_query( $query, $params ) {
        $query['orderby'] = 'meta_value';
        $query['order'] = 'ASC';
        $query['meta_query'] = array(array('key' => 'custom_price'));
        return $query;
    }
    add_filter( 'avia_post_grid_query', 'custom_post_grid_query', 10, 2);

    Best regards,
    Josue

    #350509

    A big thank you for the quick response Josue.

    Is it possible to use the “excerpt” value instead of “custom_price” for sorting?
    Because I want to use it to display the prices in the “grid portfolio” in order not to have to enter the data twice.

    I prefer this because the website is bilingual (WPML) I’ll have to use a different format for the price. (“$” is after in french and is before in english)

    I will provide you, my admin access and page link if it can be useful for you.

    Thank you again.

    #350518
    This reply has been marked as private.
    #350519
    This reply has been marked as private.
    #350545

    Hi!

    As far as i know that’s not possible, the main reason being that the excerpt can contain HTML tags which would cause a big mess if used as an orderby parameter, here’s the list of values you can set as orderby:
    http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

    Cheers!
    Josue

    #353246

    Again thank you for the reply,

    When I add custom code, there are others that appear when the page is published.

    Here is the list:

    – breadcrumb_parent
    – footer
    – header_title_bar
    – header_transparency
    – layout
    – sidebar

    Is it possible to not displayed?

    Also, how can i display the price (custom_price field) in the portfolio grid (under de title) and in the portfolio page in order to enter the price only once?

    Many thanks.

    #353329

    Hi!

    Try the following, open /enfold/config-templatebuilder/avia-shortcodes/portfolio.php and look for this part (~470):

    $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
    $output .= '<header class="entry-content-header">';
    $output .= "<h3 class='grid-entry-title entry-title' $markup><a href='{$title_link}' title='".esc_attr(strip_tags($title))."'>".$title."</a></h3>";
    $output .= '</header>';

    Change it to:

    $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
    $output .= '<header class="entry-content-header">';
    $output .= "<h3 class='grid-entry-title entry-title' $markup><a href='{$title_link}' title='".esc_attr(strip_tags($title))."'>".$title."</a></h3>";
    $output .= "CUSTOM META CODE HERE"
    $output .= '</header>';

    To do this modification using child theme shortcodes:
    http://kriesi.at/documentation/enfold/add-new-or-replace-advanced-layout-builder-elements-from-child-theme/

    Cheers!
    Josue

    #357115

    Hello Josue,

    I know a few basics in programming, but I’m not a programmer.

    That said, I am not able to display the prices in the portfolio boxes.

    I tried to replace “custom_markup” with “custom_price” that I use in my custom fields, but in vain.

    And what does ($ output. = “CUSTOM META HERE CODE”)?
    What should I replace it with “custom meta code here”?

    Note that I use a child theme and I added the command lines as mentioned in your answer.
    I also replaced the lines requested in portfolio.php file I copied to my child theme.

    Here’s the code displayed in my functions file:

    <?php
    
    /*
    * Add your own functions here. You can also copy some of the theme functions into this file. 
    * WordPress will use those functions instead of the original functions then.
    */
    
    /*
     * add option to edit elements via css class
     */
    // add_theme_support('avia_template_builder_custom_css');
    
    // enable custom fields for Portfolio items
    add_filter('avf_portfolio_cpt_args', 'avf_portfolio_add_custom_fields', 1);
    function avf_portfolio_add_custom_fields($args) {
    $args['supports'] = array('title','thumbnail','excerpt','editor','comments', 'custom-fields');
    return $args;
    }
    
    // alter the portfolio grid order
    function custom_post_grid_query( $query, $params ) {
        $query['orderby'] = 'meta_value';
        $query['order'] = 'DESC';
        $query['meta_query'] = array(array('key' => 'custom_price'));
        return $query;
    }
    add_filter( 'avia_post_grid_query', 'custom_post_grid_query', 10, 2);
    
    // Add new or replace Advanced Layout Builder elements from Child Theme
    add_filter('avia_load_shortcodes', 'avia_include_shortcode_template', 15, 1);
    function avia_include_shortcode_template($paths)
    {
    	$template_url = get_stylesheet_directory();
        	array_unshift($paths, $template_url.'/shortcodes/');
    
    	return $paths;
    }

    Again thank you for your help. :)

    #357252
    This reply has been marked as private.
    #357337

    Hi!

    You need to create a /shortcodes/ folder in your child theme directory and clone (+modification) the portfolio.php parent theme file there.

    Now add a new folder in your child theme directory called shortcodes. If you copy an element from enfold>config-templatebuilder>avia-shortcodes to this folder it will replace the one in the parent and be used instead. You can also add new ones using the other shortcode elements as examples.

    http://kriesi.at/documentation/enfold/add-new-or-replace-advanced-layout-builder-elements-from-child-theme/

    Cheers!
    Josue

    #357957

    Sorry but I do not read everything considering I had to copy the same path as in the original folders of the theme.

    By cons, if we simply returns the fact to sort items in portfolio price range with custom fields, it does not work.

    It’s mostly what I need at the base.

    I also removed the “Add new or replace Advanced Layout Builder Elements from Child Theme” to be sure it does not create conflict.

    So here’s what’s in my functions.php file in the child theme:

    <?php
    
    /*
    * Add your own functions here. You can also copy some of the theme functions into this file. 
    * WordPress will use those functions instead of the original functions then.
    */
    
    /*
     * add option to edit elements via css class
     */
    // add_theme_support('avia_template_builder_custom_css');
    
    // enable custom fields for Portfolio items
    add_filter('avf_portfolio_cpt_args', 'avf_portfolio_add_custom_fields', 1);
    function avf_portfolio_add_custom_fields($args) {
    $args['supports'] = array('title','thumbnail','excerpt','editor','comments', 'custom-fields');
    return $args;
    }
    
    // alter the portfolio grid order
    function custom_post_grid_query( $query, $params ) {
        $query['orderby'] = 'meta_value';
        $query['order'] = 'DESC';
        $query['meta_query'] = array(array('key' => 'custom_price'));
        return $query;
    }
    add_filter( 'avia_post_grid_query', 'custom_post_grid_query', 10, 2);
    
    

    Thank you.

    PS – The extension “WPML” can there be a conflict?

    #358149

    Hey!

    Alright. On portfolio.php, replace the code with this:

    $output .= '<header class="entry-content-header">';
                            $output .= "<h3 class='grid-entry-title entry-title' $markup><a href='{$title_link}' title='".esc_attr(strip_tags($title))."'>".$title."</a></h3>";
    						$estate_price = get_post_meta( $the_id, 'estate_price', true );
    						$output .= "<span class='estate_price'>{$estate_price}</span>";
                            $output .= '</header>';		

    On functions.php, replace the order parameter with this:

    function custom_post_grid_query( $query, $params ) {
        $query['orderby'] = 'meta_value_num';
        $query['order'] = 'DESC';
        return $query;
    }
    add_filter( 'avia_post_grid_query', 'custom_post_grid_query', 10, 2);

    Create a custom field on the portfolio items called estate_price then enter a price value like $ 9.99. I know the custom fields is not a beautiful solution but it works. If you want something more sophisticated that this one, you might need to hire a freelance developer.

    Regards,
    Ismael

    #358381

    Thank you Ismael,

    This works for the display of the prices on the portfolio.php child theme. By the way, I replaced the variable “estate_price” by “custom_price ” because it was already used for all entries.

    Sorting does not work though.

    I tried to replace
    $ query ['orderby'] = 'meta_value_num';
    by
    $ query ['orderby'] = 'custom_price';
    but in vain.

    Any other ideas please?

    • This reply was modified 10 years ago by nparent.
    #358975

    Hey!

    You don’t need to replace the order parameters.

    function custom_post_grid_query( $query, $params ) {
        $query['orderby'] = 'meta_value_num';
        $query['order'] = 'DESC';
        return $query;
    }
    add_filter( 'avia_post_grid_query', 'custom_post_grid_query', 10, 2);

    Please apply custom fields with different value(example: $ 9.99, $ 8.99 and $ 7.77) on 3 posts then test it. Change DESC to ASC or vice versa.

    Best regards,
    Ismael

    #622536

    is it possible to see the live site on this to help other Enfold users?
    Thanks
    Jon

    #622928

    That would be up to @nparent, i’ll leave this thread open.

    Best regards,
    Josue

Viewing 17 posts - 1 through 17 (of 17 total)
  • You must be logged in to reply to this topic.