Skip to content

Instantly share code, notes, and snippets.

@bolstad
Created May 1, 2012 12:35
Show Gist options
  • Save bolstad/2567701 to your computer and use it in GitHub Desktop.
Save bolstad/2567701 to your computer and use it in GitHub Desktop.
Bug in wpv_filter_shortcode_start() ?
Hi, I got this strange problem when displaying a View Template on an archive page, everything was working correct and I set Layout Style to 'Table' with 'Include field names in table headings' and I got a nice table with headings.
But the Sort function wasn't working! When clicking on the headings I was linked to one of the pages listed in the table, but with the sorting parameters added to it (
(?wpv_column_sort_id=post-link&wpv_column_sort_dir=desc&wpv_paged=1&wpv_paged_max=0&wpv_widget_view_id=0&wpv_post_id=1288).
I digged trough the source of the page and found that the 'wpv-filter-form ' that handle the sorting had the action-parameter set to the random subpage, and not the current url of the archive page that I was visiting.
I search the wp-views source and and found this, wpv_filter_shortcode_start() - the function that create to form for the sorting, use get_permalink() to set the ACTION-attribute for the form. Since get_permalink() doesn't work well outside the loop and can't give a correct self refering url on the page, it will return the URL of the last post in The Loop (the views table listing).
Since the ACTION parameter in this form always should point to the current 'page' I *belive* it would be better and ok to set it to an empty variable. A patch is enclosed here:
diff --git a/wp-content/plugins/wp-views/embedded/inc/wpv-filter-embedded.php b/wp-content/plugins/wp-views/embedded/inc/wpv-filter-embedded.php
index 29cad59..12919e2 100644
--- a/wp-content/plugins/wp-views/embedded/inc/wpv-filter-embedded.php
+++ b/wp-content/plugins/wp-views/embedded/inc/wpv-filter-embedded.php
@@ -35,8 +35,8 @@ function wpv_filter_shortcode_start($atts){
if (isset($atts['hide']) && $atts['hide'] == 'true') {
$hide = ' display:none;';
}
-
- $url = get_permalink();
+
+ $url = '';
$out = '<form style="margin:0; padding:0;' . $hide . '" id="wpv-filter-' . $WP_Views->get_view_count() . '" action="' . $url . '" method="GET" class="wpv-filter-form"' . ">\n";
// add hidden inputs for any url parameters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment