R
R
Ruslan Makarov2016-02-12 19:44:01
PHP
Ruslan Makarov, 2016-02-12 19:44:01

How to "friend" Wordpress post cycles?

Good!
In a nutshell, I want to get the data of another record of an arbitrary type in the record.
For this I use:

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); // Начало цикла ?>
// контент записи

                    <?php
                    // Find connected pages
                    $connected = new WP_Query( array(
                      'connected_type' => 'post_to_page',
                      'connected_items' => get_queried_object(),
                      'nopaging' => true,
                    ) );

                    // Display connected pages
                    if ( $connected->have_posts() ) :
                    ?>

                    <h3>Related pages:</h3>
                    <ul>
                    <?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
                        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?> <?php the_ID(); ?></a></li>
                    <?php  endwhile; ?>
                    </ul>
                    <?php wp_reset_postdata(); endif;?> // Prevent weirdness


//КАК ПОКАЗАТЬ ПОЛУЧЕННЫЕ ДАННЫЕ ТУТ :) ?

<?php endwhile; // Конец цикла ?>

I got what I wanted: Link, Title, ID...
But how to put this data in a variable so that it can be used in a normal loop, and not use this huge code every time as I do now...
I know PHP at the level poke method :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Silm, 2016-02-13
@Silm

You do all the "dirty work" right in the template file.
You need to study the development documentation for Wordpress, find out in which files you need to write logic, do it there. Form an array with the data you need and pass it to the template. It remains to check whether this array was passed and display the data by running through the array in a loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question