Changeset 5122
- Timestamp:
- 10/08/2013 03:41:13 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/common/functions.php
r5051 r5122 1532 1532 // Forum/Topic/Reply Feed 1533 1533 if ( isset( $query_vars['post_type'] ) ) { 1534 1535 // Supported select query vars 1536 $select_query_vars = array( 1537 'p' => false, 1538 'name' => false, 1539 $query_vars['post_type'] => false 1534 1535 // Matched post type 1536 $post_type = false; 1537 1538 // Post types to check 1539 $post_types = array( 1540 bbp_get_forum_post_type(), 1541 bbp_get_topic_post_type(), 1542 bbp_get_reply_post_type() 1540 1543 ); 1541 1544 1542 // Setup matched variables to select 1543 foreach ( $query_vars as $key => $value ) { 1544 if ( isset( $select_query_vars[$key] ) ) { 1545 $select_query_vars[$key] = $value; 1545 // Cast query vars as array outside of foreach loop 1546 $qv_array = (array) $query_vars['post_type']; 1547 1548 // Check if this query is for a bbPress post type 1549 foreach ( $post_types as $bbp_pt ) { 1550 if ( in_array( $bbp_pt, $qv_array, true ) ) { 1551 $post_type = $bbp_pt; 1552 break; 1553 } 1554 } 1555 1556 // Looking at a bbPress post type 1557 if ( ! empty( $post_type ) ) { 1558 1559 // Supported select query vars 1560 $select_query_vars = array( 1561 'p' => false, 1562 'name' => false, 1563 $post_type => false, 1564 ); 1565 1566 // Setup matched variables to select 1567 foreach ( $query_vars as $key => $value ) { 1568 if ( isset( $select_query_vars[$key] ) ) { 1569 $select_query_vars[$key] = $value; 1570 } 1546 1571 } 1547 } 1548 1549 // Remove any empties 1550 $select_query_vars = array_filter( $select_query_vars ); 1551 1552 // What bbPress post type are we looking for feeds on? 1553 switch ( $query_vars['post_type'] ) { 1554 1555 // Forum 1556 case bbp_get_forum_post_type() : 1557 1558 // Define local variable(s) 1559 $meta_query = array(); 1560 1561 // Single forum 1562 if ( !empty( $select_query_vars ) ) { 1563 1564 // Load up our own query 1565 query_posts( array_merge( array( 1566 'post_type' => bbp_get_forum_post_type(), 1567 'feed' => true 1568 ), $select_query_vars ) ); 1569 1570 // Restrict to specific forum ID 1571 $meta_query = array( array( 1572 'key' => '_bbp_forum_id', 1573 'value' => bbp_get_forum_id(), 1574 'type' => 'numeric', 1575 'compare' => '=' 1576 ) ); 1577 } 1578 1579 // Only forum replies 1580 if ( !empty( $_GET['type'] ) && ( bbp_get_reply_post_type() === $_GET['type'] ) ) { 1572 1573 // Remove any empties 1574 $select_query_vars = array_filter( $select_query_vars ); 1575 1576 // What bbPress post type are we looking for feeds on? 1577 switch ( $post_type ) { 1578 1579 // Forum 1580 case bbp_get_forum_post_type() : 1581 1582 // Define local variable(s) 1583 $meta_query = array(); 1584 1585 // Single forum 1586 if ( !empty( $select_query_vars ) ) { 1587 1588 // Load up our own query 1589 query_posts( array_merge( array( 1590 'post_type' => bbp_get_forum_post_type(), 1591 'feed' => true 1592 ), $select_query_vars ) ); 1593 1594 // Restrict to specific forum ID 1595 $meta_query = array( array( 1596 'key' => '_bbp_forum_id', 1597 'value' => bbp_get_forum_id(), 1598 'type' => 'numeric', 1599 'compare' => '=' 1600 ) ); 1601 } 1602 1603 // Only forum replies 1604 if ( !empty( $_GET['type'] ) && ( bbp_get_reply_post_type() === $_GET['type'] ) ) { 1605 1606 // The query 1607 $the_query = array( 1608 'author' => 0, 1609 'feed' => true, 1610 'post_type' => bbp_get_reply_post_type(), 1611 'post_parent' => 'any', 1612 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ), 1613 'posts_per_page' => bbp_get_replies_per_rss_page(), 1614 'order' => 'DESC', 1615 'meta_query' => $meta_query 1616 ); 1617 1618 // Output the feed 1619 bbp_display_replies_feed_rss2( $the_query ); 1620 1621 // Only forum topics 1622 } elseif ( !empty( $_GET['type'] ) && ( bbp_get_topic_post_type() === $_GET['type'] ) ) { 1623 1624 // The query 1625 $the_query = array( 1626 'author' => 0, 1627 'feed' => true, 1628 'post_type' => bbp_get_topic_post_type(), 1629 'post_parent' => bbp_get_forum_id(), 1630 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ), 1631 'posts_per_page' => bbp_get_topics_per_rss_page(), 1632 'order' => 'DESC' 1633 ); 1634 1635 // Output the feed 1636 bbp_display_topics_feed_rss2( $the_query ); 1637 1638 // All forum topics and replies 1639 } else { 1640 1641 // Exclude private/hidden forums if not looking at single 1642 if ( empty( $select_query_vars ) ) 1643 $meta_query = array( bbp_exclude_forum_ids( 'meta_query' ) ); 1644 1645 // The query 1646 $the_query = array( 1647 'author' => 0, 1648 'feed' => true, 1649 'post_type' => array( bbp_get_reply_post_type(), bbp_get_topic_post_type() ), 1650 'post_parent' => 'any', 1651 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ), 1652 'posts_per_page' => bbp_get_replies_per_rss_page(), 1653 'order' => 'DESC', 1654 'meta_query' => $meta_query 1655 ); 1656 1657 // Output the feed 1658 bbp_display_replies_feed_rss2( $the_query ); 1659 } 1660 1661 break; 1662 1663 // Topic feed - Show replies 1664 case bbp_get_topic_post_type() : 1665 1666 // Single topic 1667 if ( !empty( $select_query_vars ) ) { 1668 1669 // Load up our own query 1670 query_posts( array_merge( array( 1671 'post_type' => bbp_get_topic_post_type(), 1672 'feed' => true 1673 ), $select_query_vars ) ); 1674 1675 // Output the feed 1676 bbp_display_replies_feed_rss2( array( 'feed' => true ) ); 1677 1678 // All topics 1679 } else { 1680 1681 // The query 1682 $the_query = array( 1683 'author' => 0, 1684 'feed' => true, 1685 'post_parent' => 'any', 1686 'posts_per_page' => bbp_get_topics_per_rss_page(), 1687 'show_stickies' => false 1688 ); 1689 1690 // Output the feed 1691 bbp_display_topics_feed_rss2( $the_query ); 1692 } 1693 1694 break; 1695 1696 // Replies 1697 case bbp_get_reply_post_type() : 1581 1698 1582 1699 // The query 1583 1700 $the_query = array( 1584 'author' => 0,1585 'feed' => true,1586 'post_type' => bbp_get_reply_post_type(),1587 'post_parent' => 'any',1588 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),1589 1701 'posts_per_page' => bbp_get_replies_per_rss_page(), 1590 ' order' => 'DESC',1591 ' meta_query' => $meta_query1702 'meta_query' => array( array( ) ), 1703 'feed' => true 1592 1704 ); 1593 1705 1594 // Output the feed 1595 bbp_display_replies_feed_rss2( $the_query ); 1596 1597 // Only forum topics 1598 } elseif ( !empty( $_GET['type'] ) && ( bbp_get_topic_post_type() === $_GET['type'] ) ) { 1599 1600 // The query 1601 $the_query = array( 1602 'author' => 0, 1603 'feed' => true, 1604 'post_type' => bbp_get_topic_post_type(), 1605 'post_parent' => bbp_get_forum_id(), 1606 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ), 1607 'posts_per_page' => bbp_get_topics_per_rss_page(), 1608 'order' => 'DESC' 1609 ); 1610 1611 // Output the feed 1612 bbp_display_topics_feed_rss2( $the_query ); 1613 1614 // All forum topics and replies 1615 } else { 1616 1617 // Exclude private/hidden forums if not looking at single 1618 if ( empty( $select_query_vars ) ) 1619 $meta_query = array( bbp_exclude_forum_ids( 'meta_query' ) ); 1620 1621 // The query 1622 $the_query = array( 1623 'author' => 0, 1624 'feed' => true, 1625 'post_type' => array( bbp_get_reply_post_type(), bbp_get_topic_post_type() ), 1626 'post_parent' => 'any', 1627 'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ), 1628 'posts_per_page' => bbp_get_replies_per_rss_page(), 1629 'order' => 'DESC', 1630 'meta_query' => $meta_query 1631 ); 1632 1633 // Output the feed 1634 bbp_display_replies_feed_rss2( $the_query ); 1635 } 1636 1637 break; 1638 1639 // Topic feed - Show replies 1640 case bbp_get_topic_post_type() : 1641 1642 // Single topic 1643 if ( !empty( $select_query_vars ) ) { 1644 1645 // Load up our own query 1646 query_posts( array_merge( array( 1647 'post_type' => bbp_get_topic_post_type(), 1648 'feed' => true 1649 ), $select_query_vars ) ); 1650 1651 // Output the feed 1652 bbp_display_replies_feed_rss2( array( 'feed' => true ) ); 1653 1654 // All topics 1655 } else { 1656 1657 // The query 1658 $the_query = array( 1659 'author' => 0, 1660 'feed' => true, 1661 'post_parent' => 'any', 1662 'posts_per_page' => bbp_get_topics_per_rss_page(), 1663 'show_stickies' => false 1664 ); 1665 1666 // Output the feed 1667 bbp_display_topics_feed_rss2( $the_query ); 1668 } 1669 1670 break; 1671 1672 // Replies 1673 case bbp_get_reply_post_type() : 1674 1675 // The query 1676 $the_query = array( 1677 'posts_per_page' => bbp_get_replies_per_rss_page(), 1678 'meta_query' => array( array( ) ), 1679 'feed' => true 1680 ); 1681 1682 // All replies 1683 if ( empty( $select_query_vars ) ) { 1684 bbp_display_replies_feed_rss2( $the_query ); 1685 } 1686 1687 break; 1706 // All replies 1707 if ( empty( $select_query_vars ) ) { 1708 bbp_display_replies_feed_rss2( $the_query ); 1709 } 1710 1711 break; 1712 } 1688 1713 } 1689 1714
Note: See TracChangeset
for help on using the changeset viewer.