Title: php if does not work
Last modified: August 31, 2016

---

# php if does not work

 *  Resolved [elenis r.](https://wordpress.org/support/users/elenis1517/)
 * (@elenis1517)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-if-does-not-work-1/)
 * I tried to use the following code in a widget, but it does not work and it breaks
   the page.
    Precisely, the portfolio tags are correctly displayed, whilst the 
   second part of the code – project url etc. – is not accepted and breaks the page.
   Any help will be appreciated.
 *     ```
       <?php if(get_the_term_list($post->ID, 'portfolio_tags', '', '', '')): ?>
       					<div class="project-info-box">
       						<h4><?php echo __('Tags', 'Avada') ?>:</h4>
       						<div class="project-terms">
       							<?php echo get_the_term_list($post->ID, 'portfolio_tags', '', '', ''); ?>
       						</div>
       					</div>
       					<?php endif; ?>
       					<?php if(get_post_meta($post->ID, 'pyre_project_url', true) && get_post_meta($post->ID, 'pyre_project_url_text', true)):
       						$link_target = '';
       						if ( fusion_get_option( 'portfolio_link_icon_target', 'link_icon_target', $post->ID ) == '1' ||
       							 fusion_get_option( 'portfolio_link_icon_target', 'link_icon_target', $post->ID )  == 'yes'
       						) {
       							$link_target = ' target="_blank"';
       						}
       					?>
       ```
   
 * [https://wordpress.org/plugins/php-code-widget/](https://wordpress.org/plugins/php-code-widget/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [10 years, 3 months ago](https://wordpress.org/support/topic/php-if-does-not-work-1/#post-7058042)
 * Well, first, you didn’t declare the $post as a global, so it won’t be a global.
   Code in the PHP Widget runs in a function context, not the global context.
 * See the FAQ: [https://wordpress.org/plugins/php-code-widget/faq/](https://wordpress.org/plugins/php-code-widget/faq/)
 * Second, the value of $post is uncertain when you’re outside [The Loop](https://codex.wordpress.org/The_Loop),
   which widgets generally are.
 * You should put your code into the theme instead.

Viewing 1 replies (of 1 total)

The topic ‘php if does not work’ is closed to new replies.

 * ![](https://ps.w.org/php-code-widget/assets/icon.svg?rev=992095)
 * [PHP Code Widget](https://wordpress.org/plugins/php-code-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/php-code-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/php-code-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/php-code-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/php-code-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/php-code-widget/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/php-if-does-not-work-1/#post-7058042)
 * Status: resolved