Method to use php in WordPress functions.php? best way?

enter image description here

What i am trying to achieve is this

I have created a custom post(offer), i have another custom post created (listing).

I want to add a metabox in listing, which will recieve check list of all offers

i have achieved this as shown in image using code below.

function op_register_menu_meta_box() {
    esc_html__( 'Custom offers Checklist (select any 2)', 'text-domain' ),
add_action( 'add_meta_boxes_listing', 'op_register_menu_meta_box' );
function op_render_menu_meta_box() {
// Metabox content
$getPostsToSelect = get_posts('post_type=offers&numberposts=-1');
foreach ($getPostsToSelect as $aPostsToSelect) {
      value='<?php echo $aPostsToSelect->ID ?>'
    <?php echo $aPostsToSelect->post_title;
</label><br />

Now what what i want to get is out of the several checklist of offers, we can select two offers by checking them.

And then when we publish the listing, the checked offers will be printed on archive-offers.php

On edit page, there are lists of Custom posts(offer) in metabox named Custom offer,

how can i select the two out of them and then print those two at any place?

I need to achieve this, please help me!

Read more here:: Method to use php in WordPress functions.php? best way?

Leave a Reply

Your email address will not be published. Required fields are marked *