• i want to show the custom post type links in my custom frontend form to insert post via wp insert post…

    i have done it for category but i didnt know how to show custom post type:

    example code for category:

    <select  name="cats[]" required="" id="choices-multiple-remove-button" placeholder="Select Category" multiple>
        <?php 
       
    
    $categories = get_categories( array(
                'type'        => 'post',
                'child_of'    => 0,
                'parent'      => '',
                'orderby'     => 'name',
                'order'       => 'ASC',
                'hide_empty'  => false,
                'hierarchical'=> 1,
                'exclude'     => '',
                'include'     => '',
                'number'      => '',
                'taxonomy'    => 'category',
                'pad_counts'  => false 
            ) );
      foreach ( $categories as $category ) :
    
        echo '<option value="' . $category->term_id . '">' . $category->name . '</option>';
    
      endforeach;
    								?></select>
                            </div>
Viewing 7 replies - 1 through 7 (of 7 total)
  • Something like this?

    $posts = get_posts (array (
        'numberposts' => -1,   // -1 returns all posts
        'post_type' => 'my_custom_post_type',
        'orderby' => 'title',
        'order' => 'ASC'
    ));
    <select name="my_great_select">
        <?php foreach ($posts as $post): ?>
            <option value="<?php echo $post->ID; ?>"><?php echo $post->post_title; ?></option>
        <?php endforeach; ?>
    </select>
    Thread Starter rajdharshini1430

    (@rajdharshini1430)

    can i replace this <?php echo $post->post_title; ?> to custom field name as <?php echo get_field(‘salary_details’);?>

    Update: its working fine with custom field

    I don’t believe so. I don’t use ACF myself, but you’re not actually using a WordPress Loop, so normally that won’t work for you. You can try it, and it might work.

    Or.. you could look at the ACF docs and do this…

    <?php echo get_field ('myacf', $post->ID); ?>

    Passing in the post ID gets the value for that post, so that should work.

    Thread Starter rajdharshini1430

    (@rajdharshini1430)

    Finally i have done it but the post link not inserting on post after i submited the frontend post

    <select  name="orglink" required="" id="choices-multiple-remove-button" placeholder="Select Category" multiple>    <?php 
    	$posts = get_posts (array (
        'numberposts' => -1,   // -1 returns all posts
        'post_type' => 'organization',
        'orderby' => 'title',
        'order' => 'ASC'
    ));
    	foreach ($posts as $post): ?>
    	<option value="<a href="<?php echo the_permalink(); ?>"><?php echo get_field('salary_details');?></a>"><?php echo get_field('salary_details');?></option>
        <?php endforeach; ?>
    </select>

    while visiting a post no page link was inserted

    which means if I select custom post type on the frontend form and I submitted that form into WordPress then the selected custom post type should insert like My CUSTOM POST NAME. like hyperlink

    Thread Starter rajdharshini1430

    (@rajdharshini1430)

    Helo??

    Hi, @rajdharshini1430,

    You cannot use the the_permalink() method here. The the_permalink() method can only be used inside the WordPress loop.

    First, you have to get the post permalink using the get_post_permalink() method.

    Try this code inside the foreach loop:
    <option value="<a href="<?php echo get_post_permalink($post->ID); ?>"><?php echo get_field('salary_details');?></a>"><?php echo get_field('salary_details');?></option>

    I hope this helps ??

    Thread Starter rajdharshini1430

    (@rajdharshini1430)

    <option value=”<?php echo the_permalink(); ?>“><?php echo get_field(‘salary_details’);?>“><?php echo get_field(‘salary_details’);?></option>

    this code is working perfectly but if I select multiple post links but it is inserting only one link on the content

    for example: if I select test1 and test 2 and submitted it
    after I viewed my published post the first selected test1 link is only inserting..??

    i have given this name in ‘.$_POST[‘orglink’].’ on content while inserting

    I want like this I final output: test1, test2 by Clickable link

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘how to show custom post type in multi select’ is closed to new replies.