Viewing 1 replies (of 1 total)
  • Plugin Author cactus.cloud

    (@bortpress)

    Not without altering the plugin. Sorting by custom fields is not a standard WordPress feature – but it is possible with a little SQL and PHP.

    Please note that the results may not be 100% in order due to the masonry layout – images may be rearranged on the fly to fit the screen. However, things should be more or less in order.

    You could edit the masonry-post-gallery.php file in the plugin.

    Option 1: An inefficient option could be to add a sorting algorithm at around line 229 to sort the results by custom post.

    Option 2: Alternatively, you could rewrite the search query. The search arguments are on line 218 and the search is initiated on line 228 using get_posts(). You could replace this with a custom query string (see http://codex.ww.wp.xz.cn/Displaying_Posts_Using_a_Custom_Select_Query). Here is a snippet that I copied from the link above.

    $querystr = "
        SELECT $wpdb->posts.*
        FROM $wpdb->posts, $wpdb->postmeta
        WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
        AND $wpdb->postmeta.meta_key = 'tag'
        AND $wpdb->postmeta.meta_value = 'email'
        AND $wpdb->posts.post_status = 'publish'
        AND $wpdb->posts.post_type = 'post'
        AND $wpdb->posts.post_date < NOW()
        ORDER BY $wpdb->posts.post_date DESC
     ";
    
     $lastposts = $wpdb->get_results($querystr, OBJECT);

    The array of posts is stored in the $lastposts variable.

    This could theoretically replace the get_posts in the plugin, though it may require a little trial and error to get right.

    So, yes it is possible but it may require a little work.

Viewing 1 replies (of 1 total)

The topic ‘Post Order By Custom Field value’ is closed to new replies.