LPH
Well-known member
The XenForo_Model_Post has several different means to grab posts based on $threadId.
This is the code developed up to the point of realizing the first post is included.
The question really is ... can I simply use the $key === 0 ?
This appears to work but will there be any problems with it in the future?
Does anyone have any suggestions?
- getPostsInThread
- getPostsInThreadSimple
- getPostIdsInThread
This is the code developed up to the point of realizing the first post is included.
PHP:
// Get WordPress post_id for Post
$wp_post = get_post( $post_id );
// Get XenForo thread_id based on WP post_id
$threadId = get_post_meta( $wp_post->ID, 'thread_id', true );
// Get all posts based on thread_id
/** @var $postdModel XenForo_Model_Thread */
$postModel = XenForo_Model::create( 'XenForo_Model_Post' )->getModelFromCache( 'XenForo_Model_Post' );
/** @var $postModel XenForo_Model_Post $posts */
$postIds = $postModel->getPostIdsInThread($threadId, $ordered = true);
foreach ( $postIds as $postId ) {
// Returns ALL post ids
echo '<pre>' . var_export( $postId ) . '<br /></pre>';
}
The question really is ... can I simply use the $key === 0 ?
PHP:
foreach ( $postIds as $key => $postId ) {
if ( $key === 0 ) continue;
echo '<pre>' . var_export( $postId ) . '<br /></pre>';
}
This appears to work but will there be any problems with it in the future?
Does anyone have any suggestions?
Last edited: