Hi I have this problem :( :
How I can validate when you have five posts with the same tag automatically generate a custom_post_type with the name of the tag and this custom_post_type act as a tag page?
I am developing a plugin but I can not create the dynamically custom_post_type, this is my code. I test it calling this in my index.php <?php cus_post(); ?>, but just got validate if(countRepeat($tags_arr[$i],$tags_arr)== 5) and can´t create the custom_post_type (register_post_type). I notice that when I write just this :function cus_post(){
register_post_type('prueba',
array(
'labels' => array(
'name' => __($tags_arr[0]),
'singular_name' => __($tags_arr[0])
),
'public' => true,
'has_archive' => true,
)
);
}
is created.
<?php
/*
Plugin Name: Plugin-test.
Plugin URI: Url del plugin.
Description: Descripcion.
Version: Numero de versiones 1,2,..10.
Author: Nombre del autor.
Author URI: Pagina personal del autor.
*/
function cus_post(){
while(have_posts()) : the_post();
$posttags = get_the_tags();
if($posttags){
foreach($posttags as $tag){
$tags_arr[] = $tag -> name;
}
}
endwhile;
for ($i=0; $i < sizeof($tags_arr) ; $i++) {
if(countRepeat($tags_arr[$i],$tags_arr)== 5){
register_post_type('prueba',
array(
'labels' => array(
'name' => __($tags_arr[0]),
'singular_name' => __($tags_arr[0])
),
'public' => true,
'has_archive' => true,
)
);
}
function countRepeat($value, array $array){
$count = 0;
foreach($array as $k => $v)
{
if((string)$v == (string)$value)
{
++$count;
}
}
return $count;
}
}
add_action('init','cus_post');
?>