0

my wordpress site urls like this: https://example.com/?pid=a125a5&lang=en and query of my archive page like this:

<?php

$the_slug = get_query_var('pid');

if ($the_slug){

if ( $post = get_page_by_path( $the_slug, OBJECT, 'myposttype' ) )
    $id = $post->ID;
else
    $id = 0;
?>

<?php get_header(); ?>
<div class="warpper">



    <?php ;
    $args = array(
        'name'        => $the_slug,
        'post_type'   => 'myposttype',
        'post_status' => 'publish',
        'numberposts' => 1,
    );
    $query = new WP_Query( $args );
    if ( $query->have_posts() ) :   while ( $query->have_posts() ) : $query->the_post();    ?>

<?php the_title(); ?>

<?php endwhile; else: ?><?php endif; ?>
<php } else{...};

its work but commands like is_single() return false and wordpress not showing edit post in admin bar.

0

To show single page for your Custom Post Type you can use single-post-type.php file where you need to add your post type name after single- and use a query on this file. WordPress will use this file to show a single page of your CPT.

  • then how i can change single page url to this? example.com/?pid=a125a5&lang=en – Jerry Apr 22 at 12:00
  • You don't need to change URL, URL remains the same but your CPT will use a single-post-type.php template rather than single.php. You can still get the get_query_var('pid'); as above without checking is_single(). – ashiish.me Apr 22 at 12:07
  • im moving my site from another cms to wordpress for google index links must be same – Jerry Apr 22 at 12:16
  • Yes please check Settings > Permalinks for URL. Default URL of WordPress posts are similar to the one you have now. – ashiish.me Apr 23 at 6:45
0

The is_single() function will return always false in the archive page template. Cause, the page is archive page template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.