$post_title

This topic contains 7 replies, has 2 voices, and was last updated by  Paolo 8 years, 2 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #159434

    EH
    Expired Member
    Post count: 96

    Is the post title stored somewhere where I could use it inside my functions.php?

    Here is what I’m trying to do. I’m trying to set a variable with the post_tile then I’m looking for all posts tagged with the variable. Here is my function.

    
    
            function posts_by_dir_tag(){
            $content_tag = $post_title;
            $second_query = new WP_Query( array( 'tag_slug__in' => array( $content_tag ) ) );
    
            // The Loop
            while( $second_query->have_posts() ) : $second_query->the_post();?>
            
             <a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
            
            <?php
                endwhile;
    
            wp_reset_postdata();
            }
            add_action ('geodir_article_close','posts_by_dir_tag');
    #159508

    EH
    Expired Member
    Post count: 96

    I think I actually got it working with:

    
    
    
     function posts_by_dir_tag(){
            if (geodir_is_geodir_page()) {    
            
            $post_title = the_title();
            $second_query = new WP_Query( array( 'tag_slug__in' => array( $post_title ) ) );
    
            // The Loop
            while( $second_query->have_posts() ) : $second_query->the_post();?>
            
             <a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
            
            <?php
                endwhile;
    
            wp_reset_postdata();
            }}
            
            add_action ('geodir_article_close','posts_by_dir_tag');
    #159510

    EH
    Expired Member
    Post count: 96

    Nevermind it’s not working after all.

    #159511

    EH
    Expired Member
    Post count: 96

    Okay NOW I think I have it working.

    
    
            //Add tagged content 
            function posts_by_dir_tag(){
            if (geodir_is_geodir_page()) {    
            
            $post_tag = get_the_title($post->post_title );
            $second_query = new WP_Query( array( 'tag_slug__in' => array( $post_tag) ) );
            }
            // The Loop
            while( $second_query->have_posts() ) : $second_query->the_post();?>
            
            <a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
            
            <?php
                endwhile;
             wp_reset_postdata();
            }
            
            add_action ('geodir_article_close','posts_by_dir_tag');
    #159527

    EH
    Expired Member
    Post count: 96

    The one thing I can’t seem to figure out is how to show this if they are package_id = 2 or is_featured.

    #159618

    EH
    Expired Member
    Post count: 96

    I’m trying to get the package_id here so I can only display posts if they are paid members but for the life of me I can’t seem to get the package id. I don’t know what I’m doing wrong.

    
    
            //Add tagged content 
            function posts_by_dir_tag(){
            
            $post_tag = get_the_title($post->post_title );
            $price_details = geodir_get_post_meta($post_id, 'package_id');
            
            echo $price_details; 
            
            $second_query = new WP_Query( array( 'tag_slug__in' => array( $post_tag) ) );
            
            // The Loop
            while( $second_query->have_posts() ) : $second_query->the_post();?>
            
            <a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
            
            <?php
            endwhile; 
             wp_reset_postdata();
            }
           
            add_action ('geodir_after_main_content', 'posts_by_dir_tag');
    #159644

    EH
    Expired Member
    Post count: 96

    Ok I figured it okay. I hope you don’t mind me posting me solutions. Hopefully they can help someone else in the future.

    In listing-details.php I did the following conditional:

    
    
     if (isset($post->is_featured) && $post->is_featured) { 
       
        add_action ('geodir_after_main_content', 'posts_by_dir_tag');
    }

    then in my own functions.php here is that function:

    
    
            //Add tagged content 
            function posts_by_dir_tag(){
             
            $post_tag = get_the_title($post->post_title);
            if (isset($post->is_featured) && $post->is_featured) {
                echo 'featured'; }
            $second_query = new WP_Query( array( 'tag_slug__in' => array( $post_tag) ) );
            
            // The Loop
            while( $second_query->have_posts() ) : $second_query->the_post();?>
    
                
            <a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
            
            <?php
            endwhile; 
             wp_reset_postdata();
            }
           
           add_action ('posts_by_dir_tag');

    it seems to be working.

    #159697

    Paolo
    Site Admin
    Post count: 31206

    Not at all, thanks for sharing! 🙂

Viewing 8 posts - 1 through 8 (of 8 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket