AIOSEO multisite posts
-
Hi averyone.
The other day I was faced with the task of displaying posts from one blog in another.
The output is customized by permalinks.I have a registered custom type. Entries of this type are output through single.php. By checking query_vars, if necessary, there is a switch to the desired blog to pull the entry.
All metadata can be retrieved without problems in this way. But there are a number of problems:
1) 404 status is transmitted in headers. I change the status to 200 when there is a missing post on the current blog.
2) AIOSEOPack does not work for this entry. Data for 404 status is taken.Any ideas how I can get this to work correctly?
My post type:
register_post_type( 'quest', array( 'menu_icon'=>'dashicons-tickets-alt', 'labels' => array( 'name' => __('Quest', 'questhunter'), 'singular_name' => __( 'Quest', 'questhunter'), 'add_new' => __('Add new quest', 'questhunter'), 'menu_name' => __( 'Quests', 'questhunter') ), 'supports'=> array('title','editor','thumbnail','page-attributes','comments'), 'public' => true, 'publicly_queryable' => true, 'hierarchical' => false, 'taxonomies' => array( 'category' ), 'has_archive' => true, 'rewrite' => array( 'slug' => 'quests' ), ) );Template rules and redirect
function custom_add_rewrite_rules() { global $wp_rewrite; add_rewrite_tag('%from_blog_id%','([^&]+)'); // add_rewrite_tag('%external%','([^&]+)'); add_rewrite_rule( '^external/([0-9]+)/([a-z-]+)[/]?$', 'index.php?post_type=quest&from_blog_id=$matches[1]&name=$matches[2]', 'top' ); // add_rewrite_endpoint( 'external', EP_PERMALINK | EP_PAGES ); $wp_rewrite->flush_rules(); } add_action('init', 'custom_add_rewrite_rules'); add_action( 'template_redirect', 'unlisted_jobs_redirect' ); function unlisted_jobs_redirect($template) { // check if is a 404 error, and it's on your jobs custom post type if( is_404()) { $blog_id = get_query_var('from_blog_id'); $postname = get_query_var('name'); if ($blog_id) { switch_to_blog($blog_id); global $wp_query, $post; $new_wp_query = new WP_Query( array( 'post_type' => 'quest', 'name' => $postname, 'from_blog_id' => $blog_id, 'quest' => $postname )); if (!empty($new_wp_query->posts)) { $wp_query = $new_wp_query; header("HTTP/1.1 200 OK"); } restore_current_blog(); } } }
The topic ‘AIOSEO multisite posts’ is closed to new replies.