Tengo tipos de publicaciones personalizadas para recetas, y dentro de eso he configurado Campos personalizados avanzados (desde el complemento)
Dentro, ese tipo de mensaje personalizado, tengo varias categorías. Dos preguntas:
1.) ¿Cómo obtengo todas las publicaciones de una categoría personalizada? Recibo cómo mostrar los campos personalizados, pero no estoy seguro de cómo llamar a todas las publicaciones desde una categoría personalizada, luego puedo mostrar su título, imagen y enlace.
2.) En un escenario de tipo de publicación personalizada, ¿es mejor configurar las categorías personalizadas o usar las categorías de publicación genéricas?
Probé los get_posts y luego los obtuve por categoría personalizada. por ejemplo
<?php
$args = array(
'posts_per_page' => 8,
'orderby' => 'rand',
'post_type' => 'recipes',
'type' => 'side-dishes',
'post_status' => 'publish'
);
$show_albums = get_posts( $args );
?>
No conozco la implementación exacta, ya que post_type es una publicación personalizada, y imagino que tendría que hacer un poco para cada uno probablemente para luego usar the_field (de ACF)
=============================================== ============ Ok, después de tomar la sugerencia de abajo, aquí está lo que tengo. Por favor, avíseme si estoy haciendo esto correctamente.
aquí está la consulta, que parece funcionar:
<?php
// The Query
$the_query = new WP_Query($args = array(
'post_type' => 'recipes',
'custom_cat' => 'side-dishes'
) );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();?>
Registré la taxonomía, pero lo que me confunde es que mi post-tipo registrado son recetas, no debería register_taxonomy ser "recetas" y no 'custom_cat? "
register_taxonomy( 'custom_cat',
array('recipes'), /* if you change the name of register_post_type( 'custom_type', then you have to change this */
array('hierarchical' => true, /* if this is true, it acts like categories */
'labels' => array(
'name' => __( 'Recipe Categories', 'bonestheme' ), /* name of the custom taxonomy */
'singular_name' => __( 'Recipe Category', 'bonestheme' ), /* single taxonomy name */
'search_items' => __( 'Search Recipe Categories', 'bonestheme' ), /* search title for taxomony */
'all_items' => __( 'All Recipe Categories', 'bonestheme' ), /* all title for taxonomies */
'parent_item' => __( 'Parent Recipe Category', 'bonestheme' ), /* parent title for taxonomy */
'parent_item_colon' => __( 'Parent Custom Category:', 'bonestheme' ), /* parent taxonomy title */
'edit_item' => __( 'Edit Custom Category', 'bonestheme' ), /* edit custom taxonomy title */
'update_item' => __( 'Update Custom Category', 'bonestheme' ), /* update title for taxonomy */
'add_new_item' => __( 'Add New Custom Category', 'bonestheme' ), /* add new title for taxonomy */
'new_item_name' => __( 'New Custom Category Name', 'bonestheme' ) /* name title for taxonomy */
),
'show_admin_column' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'custom-slug' ),
)
);
aquí está el tipo de publicación registrada:
function create_recipe() {
// creating (registering) the custom type
register_post_type( 'recipes', /* (http://codex.wordpress.org/Function_Reference/register_post_type) */
// let's now add all the options for this post type
array( 'labels' => array(
'name' => __( 'Recipes', 'bonestheme' ), /* This is the Title of the Group */
'singular_name' => __( 'Recipe', 'bonestheme' ), /* This is the individual type */
'all_items' => __( 'All Recipes', 'bonestheme' ), /* the all items menu item */
'add_new' => __( 'Add New Recipe', 'bonestheme' ), /* The add new menu item */
'add_new_item' => __( 'Add Recipe', 'bonestheme' ), /* Add New Display Title */
'edit' => __( 'Edit', 'bonestheme' ), /* Edit Dialog */
'edit_item' => __( 'Edit Recipe', 'bonestheme' ), /* Edit Display Title */
'new_item' => __( 'New Recipe Type', 'bonestheme' ), /* New Display Title */
'view_item' => __( 'View Recipe', 'bonestheme' ), /* View Display Title */
'search_items' => __( 'Search Recipes', 'bonestheme' ), /* Search Custom Type Title */
'not_found' => __( 'Nothing found in the Database.', 'bonestheme' ), /* This displays if there are no entries yet */
'not_found_in_trash' => __( 'Nothing found in Trash', 'bonestheme' ), /* This displays if there is nothing in the trash */
'parent_item_colon' => ''
), /* end of arrays */
'description' => __( "Recipes section for It's Just food", 'bonestheme' ), /* Custom Type Description */
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'query_var' => true,
'menu_position' => 4, /* this is what order you want it to appear in on the left hand side menu */
'menu_icon' => get_stylesheet_directory_uri() . '/library/images/custom-post-icon.png', /* the icon for the custom post type menu */
'rewrite' => array( 'slug' => 'recipes', 'with_front' => false ), /* you can specify its url slug */
'has_archive' => 'recipes', /* you can rename the slug here */
'capability_type' => 'post',
'hierarchical' => false,
/* the next one is important, it tells what's enabled in the post editor */
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'sticky')
) /* end of options */
); /* end of register post type */