Help

This topic contains 7 replies, has 2 voices, and was last updated by mashwebdesign mashwebdesign 7 years, 8 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #3061
    mashwebdesign
    mashwebdesign
    Participant

    Hi, Sorry site is currently on localhost so cant provide login details.

    I love the functionality available in your plugin however i have one issue. I want to customise the results my self. For example i assumed there would be a wp_query call somewhere in your files? I was going to go inside the loop and make custom calls to different custom fields such as:

    get_field(‘delay_type’) etc etc etc

    Can you please help me on how to do this?

    Adam

    #3062
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Adam!

    The plugin uses an entirely different method to parse results than the built in queries. I do not recommend modifying the code, as you will loose the changes if you upgrade the plugin.

    There are however filters and actions available, that you can use to customize the results or add/remove new ones.

    Here is a knowledgebase article about adding category titles to the result titles: https://wp-dreams.com/knowledge-base/showing-the-category-titles-in-the-result-title/
    It’s a good starting point to understand how the results structure looks like.

    Based on the example above you can replace the ‘asp_add_category_titles’ function body with something like:

    
    function asp_add_category_titles( $pageposts ) {
      var_dump($pageposts);
      return $pageposts;
    } 
    

    ..and then examining the xhr/ajax request you will see the structure of the $pageposts variable, which is an array of objects, where the objects are the results.

    Another example: https://wp-dreams.com/knowledge-base/showing-the-post-type-name-in-post-title/

    The full action and filter list is available in the plugins main directory in the actions.txt and filters.txt files.

    So using this filter you can do whatever you want with the result list. It requires a bit PHP knowledge though.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #3066
    mashwebdesign
    mashwebdesign
    Participant

    Hi mate,

    Cheers my php is average so may need some assistance. I have put the code you wrote, into my themes functions.php but it isn’t changing the search results at all like nothing is taking affect? Any ideas?

    add_filter( ‘asp_pagepost_results’, ‘asp_add_category_titles’, 1, 1 );

    function asp_add_category_titles( $pageposts ) {

    var_dump($pageposts);
    return $pageposts;

    }

    #3067
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    As I said before it’s just a guidance.

    It changes nothing, but you can check the XHR request with your browser developer tools, where besides the regular request you will see the dumped structure of the $pageposts variable.

    If you want to change the results, you need to change the content of the $pageposts variable, but before you can do that, you need to understand what’s in there, that’s why I suggested that function.

    I highly recommend reading about filters and actions first before you proceed: http://codex.wordpress.org/Plugin_API

    I don’t know what you are trying to achieve exactly, so that’s why I suggested the guidelines.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #3068
    mashwebdesign
    mashwebdesign
    Participant

    Cheers mate, thought it would var_dump() it on the page. TBH the code i need to add the $pageposts is something along the lines below. I have a whole host of different custom fields that need to be brought out into the results, do you think it is possibly:

    echo ‘<div class=”further-info”>’;

    if(get_field(‘from-to-or-at’) == ‘from-to’):

    echo ‘<p class=”fromto”><i class=”fa fa-road”></i>From: ‘ . get_field(‘from’) . ‘ To: ‘. get_field(‘to’) .'</p>’;

    elseif(get_field(‘from-to-or-at’) == ‘at’):

    echo ‘<p class=”fromto”><i class=”fa fa-road”></i> AT:’ .get_field(‘at’) . ‘</p>’;

    endif;

    echo ‘<p class=”delay-type”><i class=”fa fa-car”></i> ‘ . get_field(‘delay_type’) . ‘</p>’;

    $countin = 0;

    foreach($incidenttype as $value):

    $countin++;

    if($countin == 1):

    echo ‘<p><i class=”fa fa-cogs”></i> Incident Type: ‘ . $value . ‘</p>’;

    else:

    echo ‘<p>’ . $value . ‘</p>’;

    endif;

    endforeach;

    echo ‘<p><i class=”fa fa-clock-o”></i> ‘ . get_the_time() . ‘</p>’;

    if(get_field(‘avoid’)):

    echo ‘<p class=”avoid-p”><i class=”fa fa-warning”></i> Avoid</p>’;

    endif;

    echo ‘</div>’;

    if(get_field(‘avoid’)):

    echo ‘<i class=”fa fa-warning-large fa-warning”></i>’;

    endif;

    #3069
    mashwebdesign
    mashwebdesign
    Participant

    Alright mate, starting to understand a little bit more now.

    I am trying to concatenate the custom fields onto $pageposts->content see below:

    add_filter( ‘asp_pagepost_results’, ‘asp_show_the_post_type’, 1, 1 );

    function asp_show_the_post_type( $pageposts ) {
    foreach ($pageposts as $k=>$v) {

    // Get the post categories
    $html .= ‘<div class=”further-info”>’;

    if(get_field(‘from-to-or-at’) == ‘from-to’):

    $html .= ‘<p class=”fromto”><i class=”fa fa-road”></i>From: ‘ . get_field(‘from’) . ‘ To: ‘. get_field(‘to’) .'</p>’;

    elseif(get_field(‘from-to-or-at’) == ‘at’):

    $html .= ‘<p class=”fromto”><i class=”fa fa-road”></i> AT:’ .get_field(‘at’) . ‘</p>’;

    endif;

    $html .= ‘<p class=”delay-type”><i class=”fa fa-car”></i> ‘ . get_field(‘delay_type’) . ‘</p>’;

    $countin = 0;

    foreach($incidenttype as $value):

    $countin++;

    if($countin == 1):

    $html .= ‘<p><i class=”fa fa-cogs”></i> Incident Type: ‘ . $value . ‘</p>’;

    else:

    $html .= ‘<p>’ . $value . ‘</p>’;

    endif;

    endforeach;

    $html .= ‘<p><i class=”fa fa-clock-o”></i> ‘ . get_the_time() . ‘</p>’;

    if(get_field(‘avoid’)):

    $html .= ‘<p class=”avoid-p”><i class=”fa fa-warning”></i> Avoid</p>’;

    endif;

    $html .= ‘</div>’;

    $cats = “”;

    // Modify the post title
    $pageposts[$k]->content = $pageposts[$k]->content . $html;

    }
    var_dump($pageposts);
    return $pageposts;
    }

    It works however it doesn’t get the custom fields? Any idea why it doesn’t?

    Cheers

    #3070
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Yes. I see you are using the ACF plugin. In this case I think you need the extended version of the function, because you are not in the main loop

    so instead of:

    
    get_field('fieldname')
    

    use the:

    
    get_field('fieldname', $pageposts[$k]->id)
    

    it might work.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #3072
    mashwebdesign
    mashwebdesign
    Participant

    Cheers mate, should be able to get this to work. May i quickly pick your brains.

    Okay so i understand these are preset filters that i can hook into. And that they are in a object that i can access. But where in the files are they actually declared, looped through and echo’d out.

    Out of curiosity?

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.