Forum Replies Created
-
In reply to: Display latest post from WP
Hi, fel64, you can use wp_get_posts() instead of wp_show_posts() and then use a foreach loop, much like the examples in the WP Codex for the get_posts function
You don’t mind that pretty permalinks are not being used? I think it’s a killer, let’s hope some expert can help us.
In reply to: Display latest post from WPHi,
I am writing a plugin for BBPress that shows the latest posts from WP (if WP and BBPress are sharing the same database). It’s still in development, but it already works, you just have to write
<?php wp_show_posts(\"\" ); ?>
in any BBpress template.
As you will see, it works, but it has a problem: it does not show WP’s pretty URLs. I would like to call WP’s get_permalink() function, but it uses many WP functions that are not available when you’re in BBPress.
Any advice on how to do this? Or maybe it would be easier to read WP’s RSS?
Thanks!
Here goes the code of the plugin so far (if you don’t care about pretty permalinks, you can use it, it works):
<?php
/*
Plugin Name: WP Posts
Plugin URI: http://thesandbox.wordpress.com
Description: Get a list of WordPress posts from your bbPress (needs to be integrated with WP, sharing database)
Author: Nick Brady
Version: 0.1
Author URI: http://thesandbox.wordpress.com
Install Instructions:
- If you don't have a /my-plugins/ directory in your bbpress installaltion, create it on the same level as config.php.
- Check out: https://codex.wordpress.org/Template_Tags/get_posts
*/
function wp_get_posts($args) {
global $bbdb, $bb;
parse_str($args, $r);
if ( !isset($r['numberposts']) )
$r['numberposts'] = 5;
if ( !isset($r['offset']) )
$r['offset'] = 0;
if ( !isset($r['category']) )
$r['category'] = '';
if ( !isset($r['orderby']) )
$r['orderby'] = 'post_date';
if ( !isset($r['order']) )
$r['order'] = 'DESC';
$now = bb_current_time('mysql');
$posts = $bbdb->get_results(
\"SELECT DISTINCT * FROM \".$bb->wp_table_prefix.\"posts \" .
( empty( $r['category'] ) ? \"\" : \", \".$bb->wp_table_prefix.\"post2cat \" ) .
\" WHERE post_date <= '$now' AND (post_status = 'publish') \".
( empty( $r['category'] ) ? \"\" : \"AND \".$bb->wp_table_prefix.\"posts.ID = \".$bb->wp_table_prefix.\"post2cat.post_id AND \".$bb->wp_table_prefix.\"post2cat.category_id = \" . $r['category']. \" \" ) .
\" GROUP BY \".$bb->wp_table_prefix.\"posts.ID ORDER BY \" . $r['orderby'] . \" \" . $r['order'] . \" LIMIT \" . $r['offset'] . ',' . $r['numberposts'] );
return $posts;
}
function wp_show_posts( $args ) {
global $bb;
$posts = wp_get_posts( $args );
foreach( $posts as $post ) {
echo \"<li>n\";
echo \"<a href='\".$bb->wp_home.\"?p=\".$post->ID.\"'>\";
echo $post->post_title;
echo \"</a><br/>n\";
echo \"</li>n\";
}
}
?>
In reply to: Tags separated with commasHi, chrishajer
In the tests we have done, it does work adding a new topic and also adding new tags to an existing topic.
In reply to: Display latest post from WPthat was fast!
Very interesting, I see you’re doing both things:
– Display WP posts in bbpress forums
– Display bbpress topics in WP
Are these two different plugins? I guess it’s one for WP and one for bbpress.
Looking forward to those plugins!