Support

Account

Home Forums Front-end Issues get page link query not working

Solved

get page link query not working

  • $current_url=get_page_link();
    
      $args =
      array(
        'post_type' => 'features',
        'meta_key' => 'pagelink',
        'meta_value' => $current_url
    
        );
    
      $query = new WP_Query( $args );
    
      if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
    
         <?php
    
                if (get_field('alignment') === 'left' ) {
                   get_template_part('content','leftsided');
                 }
                 else if(get_field('alignment') === 'right' ) {
                   get_template_part('content','rightsided');
                 }
    
    ?>
    
      <?php endwhile; endif; wp_reset_postdata(); ?>
    

    i have post type called features and a field on it using page link
    but my query isn’t working for some reason
    here are some of my settings in attachments

  • solved my self just changed the field type to relation ship and return post id in and array of the page and then used this code just it case its useful to anyone

    
    
      <?php
    // get id of current page and store it in $pageid variable
    global $post;
    $pageid= $post->ID;
    //query arguments
    $args=
      array(
        'post_type' => 'features'
    
        );
    //set up query with arguments input
      $query = new WP_Query( $args );
    // run loop
      if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
    
         <?php
    
        $pagelink= get_field('pagelink');
        // get_field(pagelink) returns page id selected in the pagelink field as array with 0 as the key and the page id number as the value, then we store it in pagelink variable
    if($test[0] === $pageid){
    //if the field pagelink is the same as pageid of current page then
                if (get_field('alignment') === 'left' ) {
                   get_template_part('content','leftsided');
                 }
                 else if(get_field('alignment') === 'right' ) {
                   get_template_part('content','rightsided');
                 }
    }
    ?>
    
      <?php endwhile; endif; wp_reset_postdata(); ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘get page link query not working’ is closed to new replies.