Hi @dtszero,
Do you want to show the loop for multiple Custom Post Types?
Hi @marqas,
Yes I have 4 custom post types and I want to show all of this with the WordPress default ‘post’ on my homepage.
In my normal theme I use this code to show up all
// Show on home
function print_ani_man_posts($query) {
if( !is_admin() && $query->is_main_query() && is_home() ) {
$query->set('post_type', array('post', 'anime', 'manga', 'pelicula', 'ova'));
}
}
add_action('pre_get_posts', 'print_ani_man_posts');
# Show on home
But isn’t working with AMP.
I found an article on your blog, https://ampforwp.com/tutorials/article/modify-homepage-posts-loop-amp-version-right-way/
I leave a part of the your code:
<?php
/*
Plugin Name: AMP Home Page Modify
Version: 0.0.1
Author: Mohammed Khaled
Author URI: https://ampforwp.com/
Donate link: https://www.paypal.me/Kaludi/5
License: GPL2
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
//Use Case 2: Show posts from different Post types
function ampforwp_return_loop_args(){
// learn more to Modify args @ https://developer.wordpress.org/reference/classes/wp_query/
//remove code between these comments and replace with your code here
$q = array(
'post_type' => array( 'post', 'custom_1', 'custom_2' ),
'orderby' => 'date',
'ignore_sticky_posts' => 1,
);
return $q;
}
function ampforwp_custom_home_output(){
add_filter('ampforwp_query_args', 'ampforwp_return_loop_args');
}
add_action('amp_init','ampforwp_custom_home_output');
Thanks! I solve this,
Regards,
-
This reply was modified 7 years, 7 months ago by
dtszero. Reason: ; fix