L
L
LastGeneral2022-01-08 23:50:33
WordPress
LastGeneral, 2022-01-08 23:50:33

How to display posts of a certain category?

Added custom entry type Recipes:

/**
 * Add Post Type Recipes
 */
function super_grill_recipes() {
    $labels = array(
        'name' => _x( 'Рецепты', 'Тип записей Рецепты', 'root' ),
        'singular_name' => _x( 'Рецепты', 'Тип записей Рецепты', 'root' ),
        'menu_name' => __( 'Рецепты', 'root' ),
        'all_items' => __( 'Все рецепты', 'root' ),
        'view_item' => __( 'Смотреть рецепт', 'root' ),
        'add_new_item' => __( 'Добавить новый рецепт', 'root' ),
        'add_new' => __( 'Добавить новый', 'root' ),
        'edit_item' => __( 'Редактировать рецепт', 'root' ),
        'update_item' => __( 'Обновить рецепты', 'root' ),
        'search_items' => __( 'Искать рецепт', 'root' ),
        'not_found' => __( 'Не найдено', 'root' ),
        'not_found_in_trash' => __( 'Не найдено в корзине', 'root' ),
    );

    $args = array(
        'label' => __( 'recipes', 'root' ),
        'description' => __( 'Каталог рецептов', 'root' ),
        'labels' => $labels,
        'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        'taxonomies' => array( 'genres' ),
        'hierarchical' => false,
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => true,
        'show_in_admin_bar' => true,
        'menu_position' => 5,
        'can_export' => true,
        'has_archive' => true,
        'exclude_from_search' => false,
        'publicly_queryable' => true,
        'capability_type' => 'page',
    );

    register_post_type( 'recipes', $args );
  
  register_taxonomy( 'super_grill_recipes_categories', array('recipes'), array(
        'label'                 => 'Категории рецептов',
        'labels'                => array(
            'name'              => 'Категории рецептов',
            'singular_name'     => 'Категории   ',
            'search_items'      => 'Искать категорию',
            'all_items'         => 'Все категории',
            'parent_item'       => 'Родит. категоря',
            'parent_item_colon' => 'Родит. категоря:',
            'edit_item'         => 'Редактировать категорию',
            'update_item'       => 'Обновить категорию',
            'add_new_item'      => 'Добавить категорию',
            'new_item_name'     => 'Заголовок',
            'menu_name'         => 'Категория рецептов',
        ),
            'description' => 'Категории для рецептов',
            'public' => true,
            'show_in_nav_menus' => true,
            'show_ui' => true,
            'show_tagcloud' => false,
      'hierarchical' => true,
            'rewrite' => array( 'hierarchical' => true ),
      'show_admin_column' => true,			
      'show_in_rest' => true,
      'publicly_queryable' => true,
    )
  );
}
add_action( 'init', 'super_grill_recipes' );

Created categories:
Pork ID=5803
Pork ID=5805
We managed to display them on the product pages using ACF
<?php $recipes = get_field( 'recipes' ); ?>
  <?php if ( $recipes ) : ?>
    <ul class="woocommerce-product__recipes__list recipes-container">
    <?php foreach ( $recipes as $post_ids ) : ?>
      <li class="woocommerce-product__recipes__item recipes-item">
        <div class="recipes-img"><?php echo get_the_post_thumbnail( $post_ids, 'full'); ?></div>
        <div class="recipes-title"><h3><?php echo get_the_title( $post_ids ); ?></h3></div>
          <a href="<?php echo get_permalink( $post_ids ); ?>" class="woocommerce-product__recipes__link recipes-link"></a>
      </li>
      <?php endforeach; ?>
    </ul>
    <?php endif; ?>

But nothing comes out on the page with all the Recipes, please help, I've been really hammering with this for a very long time.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2022-01-09
@LastGeneral

and why the normal output through the archive-recipes.php template does not become outdated

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question