Note that there are some explanatory texts on larger screens.

plurals
  1. POWordPress Query Post: compare between postmeta values using meta_query argument
    text
    copied!<p>I would love to display a list of unread bbPress topics by using a shortcode (running bbPress 2 + the unread topic plugin).</p> <p>The unread plugin creates a <code>postmeta</code> timestamp called <code>bbpress_unread_posts_last_visit_X</code> (where X is the current logged in user ID). To display a list of unread topics I would search for all posts which had <code>bbpress_unread_posts_last_visit_X &lt; _bbp_last_active_time</code>.</p> <h2>current nasty solution:</h2> <p>Made use of the existing <code>[bbp-topic-index]</code> shortcode - this displays a list of all topics and handles custom bbpress theme templates etc..</p> <p>So I applied a filter to <code>bbp_after_has_topics_parse_args</code> which adds a new <code>meta_query</code> argument looking for this new unread post key <code>bbpress_unread_posts_last_visit_X</code>. I then had to filter the raw generated SQL from <code>get_meta_sql</code> in order to tweak the SQL so it would compare against the other postmeta value rather then the hardcoded value from <code>meta_query</code>.</p> <p>Can anyone see a better way to achieve this without that nasty <code>get_meta_sql</code> hack? The main problem with this quick solution is that if you click "next page" on the unread list it will go to the normal next page of all topics (unread or not).</p> <p>Code:</p> <p><a href="https://gist.github.com/dtbaker/5906404" rel="nofollow">https://gist.github.com/dtbaker/5906404</a></p> <p>Implemented here (scroll to bottom):</p> <p><a href="http://ultimateclientmanager.com/forums/" rel="nofollow">http://ultimateclientmanager.com/forums/</a></p> <p><strong>EDIT:</strong> putting this shortcode on its own page works fine and solves the pagination issue (eg: <a href="http://ultimateclientmanager.com/forums/unread-forum-posts/" rel="nofollow">http://ultimateclientmanager.com/forums/unread-forum-posts/</a> )</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload