Support » Developing with WordPress » Custom Fields not displaying.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello,

    It might be a silly question to ask by me but since we don’t have the full code have you done either global $post; before your query, or somehow assigned to $post that you are talking about posts? ๐Ÿ™‚

    By the way again as I don’t know the whole spectrum of your code the official qTranslate check is qtrans_getLanguage() not ppqtrans_getLanguage(), just in case you had them changed on the other theme and copied them with the wrong names.

    Best regards,
    Konstantinos

    • This reply was modified 3 years, 6 months ago by Konstantinos Xenos. Reason: adding the qTranslate function

    Hi Xenos,

    I did not have this before my query! I have added it to the top of the page. Is this correct? After adding this certain template tags I was testing worked properly, like calling the custom field keys. The custom field keys byline_en and byline_fr still do not appear on my post page though. Also you were correct the qtrans_getLanguage() is incorrect. This is from the original qTranslate. I have changed this to what my fork of this plugin uses which is qtranxf_getLanguage()

    Here is my updated code:

    <?php get_header(); ?>
    
    <?php global $post; ?>
    
    <main id="content">
    
    			<h1 class="product_gallery_header"><?php single_cat_title( __( '', true ) ); ?></h1>
    			
    			<div id="product_gallery" role="main">
    			
     			 <?php 	//This checks what language qTranslate has selected and returns the appropriate ShortDesc
    					if (qtranxf_getLanguage() =="en") {
    					   $key = "byline_en";
    					   $description = get_post_meta($post->ID, $key, true);
    					}
    					if (qtranxf_getLanguage() =="fr") { 
    					   $key = "byline_fr";
    					   $description = get_post_meta($post->ID, $key, true);
    					}
    				?>		
    			
    			
    			
    			
    			<?php while ( have_posts() ) : the_post(); ?>
     			
    			<div class="product_thumbnail">
    			<a href="<?php the_permalink() ?>">
    			<?php //the_post_thumbnail grabs the post's "featured image" this feature has added theme support in the child theme functions.php ?>
    			<?php the_post_thumbnail('thumbnail', array('class' => 'thumbnail')); ?>
    			</a>
    			
    			<?php //This piece of code figures out the corrosponding post_title of the featured image ?>
    			<h1 class="post_caption"><?php the_title(); ?></h1>
    			<p><?php echo $description; ?></p>
    			</div> <!-- product_thumbnail -->
    		 
    
    			<?php endwhile; // end of the loop. ?>
    			
    			<div class="clear"></div>
    
    </div><!--#product_gallery-->
    
    </main>
    
    <?php get_footer(); ?>

    I don’t know where my reply went but here it goes again !

    Okay let’s debug this a bit, to see what’s up and help you out.

    Let’s check out first if you are getting the Language value. You can put an

    $tempLang = qtranxf_getLanguage();
     echo '<span style="font-size:30px;color:red">' . $tempLang . '</span>';
     die();

    Put that just under the global $post, to see if you can actually read what language you are using. IF that returns either ‘en’ or ‘ef’ it means that qtranxf_getLanguage() is working properly.

    If that is the case next step have your language on english and inside your first if do an

    echo '<span style="font-size:30px;color:red">' . $post->ID . '</span>';
     die();

    This will just print out the current posts ID and stop the script again to see if you are getting a value there.

    If those 2 are both working then there might be something wrong with your meta.

    Try those first though to see if everything gets back correctly.

    Best regards,
    Konstantinos

    Hey Konstantinos,

    Thanks for the detailed responses! Both seem to be working for me. The first shows ‘en’ for english and the second ‘fr’ for French. These are the correct language codes.

    The second bit of code shows the post ID number.

    Any idea what could be wrong with my meta?

    Okay, now that we know for sure that all of your parameters are working.

    — Edit 1—

    Give me a moment I’ll rework everything and post it here.

    —– Edit 2—-

    <?php 
    	get_header();
    	global $post;
    	$myLang = qtranxf_getLanguage();
    ?>
    <main id="content">
    	<h1 class="product_gallery_header"><?php single_cat_title( __( '', true ) ); ?></h1>
    	<div id="product_gallery" role="main">
    		<?php 
    			while ( have_posts() ) : the_post(); 
    			
    			if ( $myLang == "en" ) {
    			   $description = get_post_meta($post->ID, "byline_en", true);
    			}
    			elseif ( $myLang == "fr" ) { 
    			   $description = get_post_meta($post->ID, "byline_fr", true);
    			}
    			?>
    			<div class="product_thumbnail">
    				<a href="<?php the_permalink(); ?>">
    					<?php the_post_thumbnail('thumbnail', array('class' => 'thumbnail')); ?>
    				</a>
    				<h1 class="post_caption"><?php the_title(); ?></h1>
    				<p><?php echo $description; ?></p>
    			</div>
    		<?php
    			endwhile; // end of the loop. 
    			?>
    		<div class="clear"></div>
    	</div><!--#product_gallery-->
    </main>
    <?php 
    	get_footer(); 
    ?>

    Try this one. Hopefully it will get you your data. If not we have to check your database entries if the ‘byline_##’ is correctly submitted there I guess.

    Best regards,
    Konstantinos

    • This reply was modified 3 years, 6 months ago by Konstantinos Xenos. Reason: reworking code
    • This reply was modified 3 years, 6 months ago by Konstantinos Xenos. Reason: adding the code

    Woah this worked! Thanks so much. You’ve been an amazing help. Would you mine explaining a little bit of what you did to fix it? I’ve been trying to work on my programming, I know some basic stuff but it’s definitely my weakest skill right now (work as a web designer, very comfortable with HTML/CSS and Photoshop)

    Thinking about it, it makes sense for the if statement checking the language to be inside the loop since the post ID will be different for each product.

    What did you change at the very end aside from organizing things better?

    Also – Aside I took a look at your portfolio earlier. Looks great!

    Again, thanks for the help.

    • This reply was modified 3 years, 6 months ago by bluedrag.
    • This reply was modified 3 years, 6 months ago by bluedrag.

    Check that code on the above post and tell me friend. You where actually missing an ‘;’ on

    <?php the_permalink() ?>

    I just realized as I was rewriting your code as well after all this time… bummer hahahah.

    Best regards,
    Konstantinos

    Oh my god. That’s so frustrating… haha.

    Thank you buddy, my portfolio is empty to be honest due to ‘copyright’ issues from the companies that I work with but I intend to fix that within the next couple of days. I’m also waiting for approval for some plugins that I uploaded recently into the directory here ๐Ÿ™‚ .

    To your code!

    The idea is to first find and declare all the vars that you want to use in your code, that’s the global + the $myLang. I usually echo everything with php even simple html instead of breaking my php with ?> all the time but I left it this way as it would be easier for you to read ( maybe ).

    Then you tell WordPress to loop through the found posts and yes check for every single post if the language is english or french. As the ID changes you correctly guessed it should be inside the loop so the ID can change accordingly with ‘en’ / ‘fr’ for each post.

    It’s a really simple concept if you think like ‘speaking’ your code lets say ๐Ÿ™‚

    Your main problem again was that missing semicolon…. hahahaha

    Anyway,

    I’m glad I could assist you in your coding road by even a bit.

    Feel free to ask any more questions in here if you stumble upon any other problems and don’t forget to mark the topic as resolved !

    I’m off to find solutions to other intriguing questions in here ๐Ÿ™‚ .

    Best regards,
    Konstantinos

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom Fields not displaying.’ is closed to new replies.