I am having a trouble with my website's pop-up widget. The problem is the pop-up appears when you enter or refresh the website but I can not close it. I click on the "X" button but nothing happens. The code:
<?php
/*
Plugin Name: WP Welcome Message
Plugin URI: http://www.a1netsolutions.com/Products/WP-Welcome-Message
Description: <strong>WP Welcome Message</strong> is a wordpress plugin, which help your to make any announcement, special events, special offer, signup message or such kind of message, displayed upon your website's visitors when the page is load through a popup box.
Version: 3.0
Author: Ahsanul Kabir
Author URI: http://www.ahsanulkabir.com/
License: GPL2
License URI: license.txt
*/
$wpwm_conf = array(
'VERSION' => get_bloginfo('version'),
'VEWPATH' => plugins_url('lib/', __FILE__),
);
function wpwm_admin_styles()
{
global $wpwm_conf;
wp_enqueue_style('wpwm_admin_styles',($wpwm_conf["VEWPATH"].'css/admin.css'));
if( $wpwm_conf["VERSION"] > 3.7 )
{
wp_enqueue_style('wpwm_icon_styles',($wpwm_conf["VEWPATH"].'css/icon.css'));
}
}
add_action('admin_print_styles', 'wpwm_admin_styles');
function wpwm_scripts_styles()
{
global $wpwm_conf;
$wpwmBoxSetly = get_option('wpwm_boxsetly');
if(!$wpwmBoxSetly){$wpwmBoxSetly=="fadeOut";}
wp_enqueue_script('wpwm_site_scripts',($wpwm_conf["VEWPATH"].'js/site_'.$wpwmBoxSetly.'.js'),array('jquery'),'',true);
wp_enqueue_style('wpwm_site_style',($wpwm_conf["VEWPATH"].'css/site.css'));
}
add_action('wp_enqueue_scripts', 'wpwm_scripts_styles');
function wpwm_defaults()
{
$wpwm_default = plugin_dir_path( __FILE__ ).'lib/default.php';
if(is_file($wpwm_default))
{
require $wpwm_default;
foreach($default as $k => $v)
{
$vold = get_option($k);
if(!$vold)
{
update_option($k, $v);
}
}
if(!is_multisite())
{
unlink($wpwm_default);
}
}
}
function wpwm_activate()
{
$wpwm_postsid = get_option( 'wpwm_postsid' );
if(!$wpwm_postsid)
{
$inputContent = 'Welcome to '.get_bloginfo('name').', '. get_bloginfo('description');
$new_post_id = wpwm_printCreatePost($inputContent);
update_option( 'wpwm_postsid', $new_post_id );
}
wpwm_defaults();
}
function wpwm_redirect()
{
$wpwm_fv = get_option('wpwm_fv');
if($wpwm_fv != 'fv')
{
echo 'Please setup your <strong>WP Welcome Message 2.0</strong> plugin. <input type="submit" value="Setup" class="button" />';
}
}
add_action( 'admin_footer', 'wpwm_redirect' );
function wpwm_admin_menu()
{
global $wpwm_conf;
if( $wpwm_conf["VERSION"] < 3.8 )
{
add_menu_page('WP Welcome Message', 'Welcome Msg', 'manage_options', 'wpwm_admin_page', 'wpwm_admin_function', (plugins_url('lib/img/icon.png', __FILE__)));
}
else
{
add_menu_page('WP Welcome Message', 'Welcome Msg', 'manage_options', 'wpwm_admin_page', 'wpwm_admin_function');
}
}
add_action('admin_menu', 'wpwm_admin_menu');
function wpwm_select( $iget, $iset, $itxt )
{
if( $iget == $iset )
{
echo '<option value="'.$iset.'" selected="selected">'.$itxt.'</option>';
}
else
{
echo '<option value="'.$iset.'">'.$itxt.'</option>';
}
}
function wpwm_update($key, $value)
{
if(isset($value) && !empty($value))
{
update_option($key, $value);
}
}
function wpwm_admin_function()
{
$wpwm_fv = get_option('wpwm_fv');
if($wpwm_fv != 'fv')
{
update_option('wpwm_fv', 'fv');
}
wpwm_update('wpwm_loc', $_POST["wpwm_loc"]);
wpwm_update('wpwm_log', $_POST["wpwm_log"]);
wpwm_update('wpwm_boxsetly', $_POST["wpwm_boxsetly"]);
wpwm_update('wpwm_bgstyle', $_POST["wpwm_bgstyle"]);
wpwm_update('wpwmTemplate', $_POST["wpwmTemplate"]);
wpwm_update('wpwm_onlyFirstVisit', $_POST["wpwm_onlyFirstVisit"]);
wpwm_update('wpwm_ststs', $_POST["wpwm_ststs"]);
$wpwmPID = get_option('wpwm_postsid');
wpwm_updatePost($_POST["wpwmeditor"], $wpwmPID);
if( isset($_POST["wpwmeditor"]) || isset($_POST["wpwmTemplate"]) )
{
echo '<div id="message" class="updated wpwm_updated"><p>Your data has been successfully saved.</p></div>';
}
global $wpwm_conf;
echo '<div id="wpwm_container">
<div id="wpwm_main">
<img src="',$wpwm_conf["VEWPATH"],'/img/uvg.png" id="wpwm_uvg" />
<h1 id="wpwm_page_title">WP Welcome Message</h1>';
?>
<div class="wpwm_box">
<div class="wpwm_box_title">Your Welcome Message
<form method="post" action="" id="wpwm_off_on"><input type="hidden" name="wpwm_ststs" value="<?php
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'on')
{
echo 'off';
}
else
{
echo 'on';
}
?>" /><input type="image" src="<?php echo $wpwm_conf["VEWPATH"]; ?>/img/<?php
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'on')
{
echo 'one-check_yes';
}
else
{
echo 'one-check_no';
}
?>.png" /></form>
</div>
<div class="wpwm_box_con">
<form method="post" action="" id="wpwm_content_form">
<?php
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'off')
{
echo '<div id="wpwm_content_disable"></div>';
}
$wpwmPID = get_option('wpwm_postsid');
$wpwmContent = get_post($wpwmPID);
$wpwmContent = $wpwmContent->post_content;
$wpwmContent = apply_filters('the_content', $wpwmContent);
$wpwmContent = str_replace(']]>', ']]>', $wpwmContent);
if( $wpwm_conf["VERSION"] < 3.3 )
{
echo '<textarea name="wpwmeditor" style="width:100%; height:300px;"></textarea>';
}
else
{
wp_editor( $wpwmContent, 'wpwmeditor', array('textarea_rows' => 20, 'textarea_name' => 'wpwmeditor') );
}
?>
<input type="submit" value="save changes" />
</form>
</div>
</div>
<div class="wpwm_box">
<div class="wpwm_box_title">Settings</div>
<div class="wpwm_box_con">
<form method="post" action="">
<div class="row">
<label>On Which Page/Pages to Display : </label>
<select name="wpwm_loc">
<?php
$wpwmLoc = get_option( 'wpwm_loc' );
wpwm_select( $wpwmLoc, 'home', 'Home Page Only' );
wpwm_select( $wpwmLoc, 'all', 'All Pages' );
?>
</select>
</div>
<div class="row">
<label>Logged-in / Not Logged-in user : </label>
<select name="wpwm_log">
<?php
$wpwm_log = get_option( 'wpwm_log' );
wpwm_select( $wpwm_log, 'log', 'Logged-in Users Only' );
wpwm_select( $wpwm_log, 'nlog', 'Not Logged-in Users Only' );
wpwm_select( $wpwm_log, 'all', 'For All' );
?>
</select>
</div>
<div class="row">
<label>Message Box Animation Style : </label>
<select name="wpwm_boxsetly">
<?php
$wpwmBoxSetly = get_option( 'wpwm_boxsetly' );
wpwm_select( $wpwmBoxSetly, 'fadeOut', 'Fade Out' );
wpwm_select( $wpwmBoxSetly, 'slideUp', 'Slide Up' );
?>
</select>
</div>
<div class="row">
<label>Template : </label>
<select name="wpwmTemplate">
<?php
$wpwmTemplate = get_option( 'wpwmTemplate' );
wpwm_select( $wpwmTemplate, 'black-color', 'Dark Color Only' );
wpwm_select( $wpwmTemplate, 'black-white-color', 'White Color Only' );
wpwm_select( $wpwmTemplate, 'white-color', 'Full White Color Only' );
wpwm_select( $wpwmTemplate, 'black-striped', 'Dark Stripes' );
wpwm_select( $wpwmTemplate, 'black-white-striped', 'White Stripes' );
wpwm_select( $wpwmTemplate, 'white-striped', 'Full White Stripes' );
wpwm_select( $wpwmTemplate, 'bootstrap', 'Bootstrap Style' );
?>
</select>
</div>
<div class="row">
<label>Only For Fist Time Visit : </label>
<select name="wpwm_onlyFirstVisit">
<?php
$wpwm_onlyFirstVisit = get_option( 'wpwm_onlyFirstVisit' );
wpwm_select( $wpwm_onlyFirstVisit, 'on', 'Enable' );
wpwm_select( $wpwm_onlyFirstVisit, 'off', 'Disable' );
?>
</select>
</div>
<input type="submit" value="save changes" />
</form>
</div>
</div>
<?php
echo '</div>
<div id="wpwm_side">
<div class="wpwm_box">';
echo '<img src="',$wpwm_conf["VEWPATH"],'/img/wp-advert-1.png" />';
echo '</div><div class="wpwm_box">';
echo '<img src="',$wpwm_conf["VEWPATH"],'/img/wp-advert-2.png" />';
echo '</div>
</div>
<div class="wpwm_clr"></div>
</div>';
}
function wpwm_content()
{
$wpwm_ststs = get_option('wpwm_ststs');
if($wpwm_ststs == 'on')
{
$wpwm_onlyFirstVisit = get_option( 'wpwm_onlyFirstVisit' );
if( $wpwm_onlyFirstVisit == "on" )
{
if( (!isset($_SESSION["wpwm_session"])) || ($_SESSION["wpwm_session"] != 'off') )
{
wpwm_popupFirst();
}
}
else
{
wpwm_popupFirst();
}
}
}
function wpwm_popupFirst()
{
$wpwm_loc = get_option( 'wpwm_log' );
if(get_option('wpwm_ststs') == 'on')
{
if( $wpwm_loc == 'log' )
{
if ( is_user_logged_in() )
{
wpwm_popupCheckPage();
}
}
elseif( $wpwm_loc == 'nlog' )
{
if ( !is_user_logged_in() )
{
wpwm_popupCheckPage();
}
}
else
{
wpwm_popupCheckPage();
}
}
}
function wpwm_popupTemp()
{
$wpwmPID = get_option( 'wpwm_postsid' );
$wpwmTemplate = get_option('wpwmTemplate');
$content_post = get_post($wpwmPID);
$wpwmContent = $content_post->post_content;
$wpwmContent = apply_filters('the_content', $wpwmContent);
$wpwmContent = str_replace(']]>', ']]>', $wpwmContent);
$session_id = session_id();
echo '
<div id="wpwm_hideBody" class="'.$wpwmTemplate.'-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
'.$wpwmContent.'
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("html, body").css({"overflow": "hidden"});
});
</script>
';
echo '<span>',get_option('wpwm_dev1'),get_option('wpwm_dev2'),get_option('wpwm_dev3'),'</span>';
}
function wpwm_popupCheckPage()
{
if( ( get_option( 'wpwm_loc' ) ) == 'home' )
{
if( is_front_page() )
{
wpwm_popupTemp();
}
}
else
{
wpwm_popupTemp();
}
}
function wpwm_sessionID()
{
if(!isset($_SESSION)){session_start();}
if(isset($_SESSION["wpwm_session"]))
{
$_SESSION["wpwm_session"] = 'off';
}
else
{
$_SESSION["wpwm_session"] = 'on';
}
}
add_action( 'wp_head', 'wpwm_sessionID' );
function wpwm_posts_init()
{
$args = array
(
'public' => false,
'publicly_queryable' => false,
'show_ui' => false,
'show_in_menu' => false,
'rewrite' => array( 'slug' => 'wpwmposts' ),
'capability_type' => 'post',
'has_archive' => false,
'supports' => array( 'title', 'editor', 'excerpt' )
);
register_post_type( 'wpwmposts', $args );
}
add_action( 'init', 'wpwm_posts_init' );
function wpwm_getCurrentUser()
{
if (function_exists('wp_get_current_user'))
{
return wp_get_current_user();
}
else if (function_exists('get_currentuserinfo'))
{
global $userdata;
get_currentuserinfo();
return $userdata;
}
else
{
$user_login = $_COOKIE["USER_COOKIE"];
$current_user = $wpdb->get_results("SELECT * FROM `".$wpdb->users."` WHERE `user_login` = '".$user_login."' ;");
return $current_user;
}
}
function wpwm_printCreatePost($inputContent)
{
$newPostAuthor = wpwm_getCurrentUser();
$newPostArg = array
(
'post_author' => $newPostAuthor->ID,
'post_content' => $inputContent,
'post_status' => 'publish',
'post_type' => 'wpwmposts'
);
$new_post_id = wp_insert_post($newPostArg);
return $new_post_id;
}
function wpwm_updatePost($inputContent, $id)
{
$newPostAuthor = wpwm_getCurrentUser();
$newPostArg = array
(
'ID' => $id,
'post_author' => $newPostAuthor->ID,
'post_content' => $inputContent,
'post_status' => 'publish',
'post_type' => 'wpwmposts'
);
$new_post_id = wp_insert_post($newPostArg);
return $new_post_id;
}
add_action('wp_footer', 'wpwm_content', 100);
register_activation_hook(__FILE__, 'wpwm_activate');
?>
Finally, I managed to find where the problem is.
echo '
<div id="wpwm_hideBody" class="'.$wpwmTemplate.'-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
'.$wpwmContent.'
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("html, body").css({"overflow": "hidden"});
});
</script>
';
And find out there is no close function going on here:
<span id="wpwm_popClose">×</span>
So changed it with this:
<span id="wpwm_popClose" onclick="document.getElementById('pwm_hideBody').style.display='none'">×</span>
but when I edit this PHP code, WordPress gives me this error:
Parse error: syntax error, unexpected 'pwm_hideBody' (T_STRING), expecting ',' or ';' in /var/www/vhosts/derinuzay.org/httpdocs/wp-content/plugins/wp-welcome-message/wp-welcome-message.php on line 337
Could you please help me out about this error?
Try to add this:
jQuery('#wpwm_popClose').click(function() {
jQuery('#wpwm_hideBody').css('display', 'none');
});
inside the:
jQuery(document).ready(function() {
jQuery("html, body").css({"overflow": "hidden"});
});
What happens if you replace
echo '
<div id="wpwm_hideBody" class="'.$wpwmTemplate.'-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
'.$wpwmContent.'
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery("html, body").css({"overflow": "hidden"});
});
</script>
';
With:
?>
<div id="wpwm_hideBody" class="<?php echo $wpwmTemplate; ?>-body">
<div id="wpwm_popBoxOut">
<div class="wpwm-box">
<div id="wpwm_popBox">
<span id="wpwm_popClose">×</span>
<?php echo $wpwmContent; ?>
<div class="cl_fix"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#wpwm_popClose').click(function() {
jQuery('#wpwm_hideBody').css('display', 'none');
});
});
</script>
<?php
Related
i iclude a wordpress media selector in my wordpress plugin.
i got this error :
Unable to create directory wp-content/uploads/2022/12. Is its parent directory writable by the server?
error
i added to this code to wp-config.php file :
`
/** WordPress değişkenlerini ve yollarını kurar. */
require_once ABSPATH . 'wp-settings.php';
define( 'UPLOADS', 'wp-content/uploads' );
`
and added to myportfolio-form.php file
<?php
add_action( 'admin_footer', 'media_selector_print_scripts' );
function media_selector_print_scripts() {
$my_saved_attachment_post_id = get_option( 'media_selector_attachment_id', 0 );
?><script type='text/javascript'>
jQuery( document ).ready( function( $ ) {
// Uploading files
var file_frame;
var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id
var set_to_post_id = <?php echo $my_saved_attachment_post_id; ?>; // Set this
jQuery('#upload_image_button').on('click', function( event ){
event.preventDefault();
// If the media frame already exists, reopen it.
if ( file_frame ) {
// Set the post ID to what we want
file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
// Open frame
file_frame.open();
return;
} else {
// Set the wp.media post id so the uploader grabs the ID we want when initialised
wp.media.model.settings.post.id = set_to_post_id;
}
// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
title: 'Select a image to upload',
button: {
text: 'Use this image',
},
multiple: false // Set to true to allow multiple files to be selected
});
// When an image is selected, run a callback.
file_frame.on( 'select', function() {
// We set multiple to false so only get one image from the uploader
attachment = file_frame.state().get('selection').first().toJSON();
// Do something with attachment.id and/or attachment.url here
$( '#image-preview' ).attr( 'src', attachment.url ).css( 'width', 'auto' );
$( '#image_attachment_id' ).val( attachment.id );
// Restore the main post ID
wp.media.model.settings.post.id = wp_media_post_id;
});
// Finally, open the modal
file_frame.open();
});
// Restore the main ID when the add media button is pressed
jQuery( 'a.add_media' ).on( 'click', function() {
wp.media.model.settings.post.id = wp_media_post_id;
});
});
</script><?php
}
function portfolio_admin_myprojects_page_handler()
{
global $wpdb;
$table = new Portfolio_MyProjects_List_Table();
$table->prepare_items();
$message = '';
if ('delete' === $table->current_action()) {
$message = '<div class="updated below-h2" id="message"><p>' . sprintf(__('Items deleted: %d', 'portfolio-admin-myresume'), count($_REQUEST['ID'])) . '</p></div>';
}
?>
<div class="wrap">
<div class="icon32 icon32-posts-post" id="icon-edit"><br></div>
<h2><?php _e('My Projects', 'portfolio-admin-myresume')?> <a class="add-new-h2"
href="<?php echo get_admin_url(get_current_blog_id(), 'admin.php?page=myprojects_form');?>"><?php _e('Add new', 'portfolio-admin-myresume')?></a>
</h2>
<?php echo $message; ?>
<form id="myprojects-table" method="POST">
<input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>"/>
<?php $table->display() ?>
</form>
</div>
<?php
}
function portfolio_admin_projects_form_page_handler()
{
global $wpdb;
$table_name = $wpdb->prefix . 'portfolio_myprojects';
$message = '';
$notice = '';
$default = array(
'ID' => 0,
'projects_name' => '',
'projects_category' => '',
'projects_link' => '',
'projects_image' => '',
'order' => '',
);
if ( isset($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], basename(__FILE__))) {
$item = shortcode_atts($default, $_REQUEST);
$item_valid = portfolio_admin_validate_myprojects($item);
if ($item_valid === true) {
if ($item['ID'] == 0) {
$result = $wpdb->insert($table_name, $item);
$item['ID'] = $wpdb->insert_id;
if ($result) {
$message = __('Item was successfully saved', 'portfolio-admin-myresume');
} else {
$notice = __('There was an error while saving item', 'portfolio-admin-myresume');
}
} else {
$result = $wpdb->update($table_name, $item, array('ID' => $item['ID']));
if ($result) {
$message = __('Item was successfully updated', 'portfolio-admin-myresume');
} else {
$notice = __('There was an error while updating item', 'portfolio-admin-myresume');
}
}
} else {
$notice = $item_valid;
}
}
else {
$item = $default;
if (isset($_REQUEST['ID'])) {
$item = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name WHERE ID = %d", $_REQUEST['ID']), ARRAY_A);
if (!$item) {
$item = $default;
$notice = __('Item not found', 'portfolio-admin-myresume');
}
}
}
add_meta_box('myprojects_form_meta_box', __('Work Details', 'portfolio-admin-myresume'), 'portfolio_admin_projects_form_meta_box_handler', 'myprojects', 'normal', 'default');
?>
<div class="wrap">
<div class="icon32 icon32-posts-post" id="icon-edit"><br></div>
<h2><?php _e('My Projects', 'portfolio-admin-myresume')?> <a class="add-new-h2"
href="<?php echo get_admin_url(get_current_blog_id(), 'admin.php?page=myprojects');?>"><?php _e('back to list', 'portfolio-admin-myresume')?></a>
</h2>
<?php if (!empty($notice)): ?>
<div id="notice" class="error"><p><?php echo $notice ?></p></div>
<?php endif;?>
<?php if (!empty($message)): ?>
<div id="message" class="updated"><p><?php echo $message ?></p></div>
<?php endif;?>
<form id="form" method="POST">
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce(basename(__FILE__))?>"/>
<input type="hidden" name="ID" value="<?php echo $item['ID'] ?>"/>
<div class="metabox-holder" id="poststuff">
<div id="post-body">
<div id="post-body-content">
<?php do_meta_boxes('myprojects', 'normal', $item); ?>
<input type="submit" value="<?php _e('Save', 'portfolio-admin-myresume')?>" id="submit" class="button-primary" name="submit">
</div>
</div>
</div>
</form>
</div>
<?php
}
function portfolio_admin_projects_form_meta_box_handler($item)
{
// Save attachment ID
if ( isset( $_POST['submit_image_selector'] ) && isset( $_POST['image_attachment_id'] ) ) :
update_option( 'media_selector_attachment_id', absint( $_POST['image_attachment_id'] ) );
endif;
wp_enqueue_media();
?>
<tbody >
<div class="formdatabc">
<form >
<div class="form2bc">
<p>
<label for="projects_name"><?php _e('Project Name:', 'portfolio-admin-myresume')?></label>
<br>
<input id="projects_name" name="projects_name" type="text" value="<?php echo esc_attr($item['projects_name'])?>"
required>
</p>
</div>
<div class="form2bc">
<p>
<label for="projects_category"><?php _e('Project Category', 'portfolio-admin-myresume')?></label>
<br>
<input id="projects_category" name="skills_percent" type="text" value="<?php echo esc_attr($item['projects_category'])?>"
required>
</p>
</div>
<div class="form3bc">
</div>
<div>
<p>
<label for="projects_link"><?php _e('Project Link:', 'portfolio-admin-myresume')?></label>
<br>
<textarea id="projects_link" name="projects_link" cols="100" rows="3" maxlength="240"><?php echo esc_attr($item['projects_link'])?></textarea>
</p>
</div>
<div class='image-preview-wrapper'>
<img id='image-preview' src='' width='100' height='100' style='max-height: 100px; width: 100px;'>
</div>
<input id="upload_image_button" type="button" class="button" value="<?php _e( 'Upload image' ); ?>" />
<input type='hidden' name='image_attachment_id' id='image_attachment_id' value=''>
</form>
</div>
</tbody>
<?php
}
`
i tried to iclude wordpress media selector to my plugin but it doesnt work.
error : Unable to create directory wp-content/uploads/2022/12. Is its parent directory writable by the server?
You need to change permissions of directories on server itself
chmod -R 777 /path/to/web-root/wp-content/uploads
(Linux example, this will change all files)
chmod 777 /path/to/web-root/wp-content
(this will change only directory itself, not all files)
I'm having trouble with some PHP alongside ACF. I'm pretty unfamiliar when it comes to PHP but here's the structure. I have a ACF Select field for a category that includes Admin, Salesperson and Clerk. I am trying to render cards for each person under each category for example
Admin
Person 1 Person 3 Person 5
Salesperson
Person 2 Person 6
Clerk
Person 7
Here's the code I have:
$members_query = new WP_Query( array(
'post_type' => 'team-member',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'asc'
) );
// abort if no members to show
if ( ! $members_query->have_posts() ) return;
// split members into two columns
$members_all = $members_query->posts;
$members_list = array();
foreach ($members_query->posts as $loop_index => $member_post ) {
$members_list[] = $member_post;
}
// use a fn to output member cards for each column
if ( ! function_exists( 'opt_render_team_member' ) ) {
function opt_render_team_member( $member_post, $id_prefix = '' ) {
$name = $member_post->post_title;
$image = get_field( 'image', $member_post->ID );
$job_title = get_field( 'job_title', $member_post->ID );
$bio = get_field( 'bio', $member_post->ID );
$certifications = get_field( 'certifications', $member_post->ID );
$category = get_field ( 'category', $member_post->ID);
?>
<div class="mb-7">
<?php if ( $image ) : ?>
<div class="team-members__headshot">
<?= wp_get_attachment_image( $image['ID'], 'medium_large' ); ?>
</div>
<?php endif; ?>
<?php if ( $name ) : ?>
<h2 class="team-members__name">
<?= $name; ?>
</h2>
<?php endif; ?>
<?php if ( $job_title ) : ?>
<h3 class="team-members__position">
<?= $job_title; ?>
</h3>
<?php endif; ?>
<?php if ( $bio ) : ?>
<?= $bio; ?>
<?php endif; ?>
<?php if ( ! empty( $certifications ) ) : ?>
<button
class="team-members__credentials-toggle"
type="button"
data-toggle="collapse"
data-target="#team-member-<?= $id_prefix; ?>"
aria-expanded="false"
aria-controls="team-member-<?= $id_prefix; ?>"
>
<?= __( 'See their credentials', 'optimize' ); ?>
</button>
<ul class="team-members__credentials collapse" id="team-member-<?= $id_prefix; ?>">
<?php foreach ( $certifications as $certification ) : ?>
<li>
<?= $certification['certification']; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<?php
}
}
?>
<div class="team-members alignfull">
<div class="container">
<div class="row d-none d-lg-flex">
<?php foreach ( $members_list as $loop_index => $member_post ) : ?>
<?php if(get_field( 'category' ) == "admin") : ?>
<div class="col-12 col-md-6 col-lg-4">
<?php opt_render_team_member( $member_post, "$loop_index" ); ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
The issue is when I add the if(get_field('category') == "admin" it shows nothing, but if I remove that if statement, I see all the members but not sorted as I would like. Any advice or ideas. Thanks!
For fun:
<?php
$members_query = new WP_Query( array(
'post_type' => 'team-member',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'asc'
) );
// abort if no members to show
if ( ! $members_query->have_posts() ) return;
// split members into two columns
$members_all = $members_query->posts;
$members_list = array();
foreach ($members_query->posts as $loop_index => $member_post ) {
$members_list[] = $member_post;
}
class TeamMemberCard
{
public function __construct(private $memberPost = null, private $idPrefix = null){}
private function hasMemberProperty(string $property): bool
{
return is_object($this->memberPost) && property_exists($this->memberPost, $property);
}
private function getMemberId(): ?int
{
if ($this->hasMemberProperty('ID')) {
return $this->memberPost->ID;
}
return null;
}
private function getImage(string $context = 'view'): null|string|array
{
$image = get_field('image', $this->getMemberId());
if ( ! is_array($image)) {
return null;
}
if ($context === 'view') {
$wpImg = wp_get_attachment_image( $image['ID'], 'medium_large' );
return <<<RETURN
<div class="team-members__headshot">
{$wpImg}
</div>
RETURN;
}
return $image;
}
private function getJobTitle(string $context = 'view'): null|string
{
$jobTitle = get_field('job_title', $this->getMemberId());
if (empty($jobTitle)) {
return null;
}
if ($context === 'view') {
return <<<RETURN
<div class="team-members__position">
{$jobTitle}
</div>
RETURN;
}
return $jobTitle;
}
private function getBio(): null|string
{
$bio = get_field('bio', $this->getMemberId());
if (empty($bio)) {
return null;
}
return $bio;
}
private function getName(string $context = 'view'): ?string
{
if ($this->hasMemberProperty('post_title')) {
if ($context === 'view') {
return <<<RETURN
<h2 class="team-members__name">
{$this->getName('false')}
</h2>
RETURN;
}
return $this->memberPost->post_title;
}
return null;
}
private function getCertifications(string $context = 'view'): null|string|array
{
$certifications = get_field( 'certifications', $this->getMemberId());
if (empty($certifications)) {
return null;
}
if ($context !== 'view') {
return $certifications;
}
$buttonValue = __('See their credentials', 'optimize');
$button = <<<BUTTON
<button
class="team-members__credentials-toggle"
type="button"
data-toggle="collapse"
data-target="#team-member-{$this->idPrefix}"
aria-expanded="false"
aria-controls="team-member-{$this->idPrefix}"
>
{$buttonValue}
</button>
BUTTON;
$certs = <<<CERTS
{$button}
<ul class="team-members__credentials collapse" id="team-member-{$this->idPrefix}">
%s
</ul>
CERTS;
$certsLi = array();
if (is_array($certifications)) {
foreach($certifications as $certification) {
if ( ! array_key_exists('certification', $certification)) {
continue;
}
$certsLi[] = <<<CERTSLI
<li>
{$certification['certification']}
</li>
CERTSLI;
}
}
return sprintf ($certs, implode('', $certsLi));
}
public function isAdmin(): bool
{
return get_field('category', $this->getMemberId()) === 'admin';
}
public function getCard(bool $echo = false): string
{
$card = <<<CARD
<div class="mb-7">
{$this->getImage()}
{$this->getName()}
{$this->getJobTitle()}
{$this->getBio()}
{$this->getCertifications()}
</div>
CARD;
if (true === $echo) {
echo $card;
}
return $card;
}
}
?>
<div class="team-members alignfull">
<div class="container">
<div class="row d-none d-lg-flex">
<?php
foreach ($members_list as $loop_index => $member_post) {
$memberCard = new TeamMemberCard($member_post, $loop_index);
if ($memberCard->isAdmin()) {
echo <<<ECHO
<div class="col-12 col-md-6 col-lg-4">
{$memberCard->getCard()}
</div>
ECHO;
}
}
?>
</div>
</div>
</div>
With this I add a custom field to a category:
add_action ( 'edit_category_form_fields', function( $tag ){
$cat_title = get_term_meta( $tag->term_id, '_pagetitle', true ); ?>
<tr class='form-field'>
<th scope='row'><label for='cat_page_title'><?php _e('Category Page Title'); ?></label></th>
<td>
<input type='text' name='cat_title' id='cat_title' value='<?php echo $cat_title ?>'>
<p class='description'><?php _e('Title for the Category '); ?></p>
</td>
</tr> <?php
});
add_action ( 'edited_category', function() {
if ( isset( $_POST['cat_title'] ) )
update_term_meta( $_POST['tag_ID'], '_pagetitle', $_POST['cat_title'] );
});
Then I try to add my own text with ajax:
function data_person(){
$catname = $_POST['catName'];
$surnameCat = $_POST["surnameCat"];
$cityCat = $_POST["cityCat"];
$catDob = $_POST["dobCat"];
$catBio = $_POST["catBio"];
$cat_ID = get_cat_ID( sanitize_title_for_query($catname) );
// Check if category exists
if($cat_ID == 0) {
$cat_name = $catname;
$cat_sur = $surnameCat;
$cat_city = $cityCat;
$cat_dob = $catDob;
$cat_bio = $catBio;
$cat_slug = sanitize_title_with_dashes($cat_name);
$my_cat = array(
'cat_name' => $cat_name,
'category_description' => $cat_bio,
'cat_title' => $cat_sur,
'category_nicename' => $cat_slug,
'category_parent' => 0
);
if( wp_insert_category( $my_cat ) ) {
echo json_encode("Category added successfully");
} else {
echo json_encode("That category already exists");
}
} else {
echo json_encode("That category already exists");
}
exit;
}
but I am not sure how to add the text to the new created custom field, this isn't working: 'cat_title' => $cat_sur, as it isn't saving the value I am sending from the input field once I click. Basically what should I put instead of 'cat_title' => ?
UPDATE
This is the full code, so in function.php we have:
add_action ( 'edit_category_form_fields', function( $tag ){
$cat_title = get_term_meta( $tag->term_id, '_pagetitle', true ); ?>
<tr class='form-field'>
<th scope='row'><label for='cat_page_title'><?php _e('Category Page Title'); ?></label></th>
<td>
<input type='text' name='cat_title' id='cat_title' value='<?php echo $cat_title ?>'>
<p class='description'><?php _e('Title for the Category '); ?></p>
</td>
</tr> <?php
});
add_action ( 'edited_category', function() {
if ( isset( $_POST['cat_title'] ) )
update_term_meta( $_POST['tag_ID'], '_pagetitle', $_POST['cat_title'] );
});
add_action( 'wp_footer', 'ajax_Person' );
function ajax_Person() { ?>
<script type="text/javascript">
jQuery("#saveperson").on("click", function(e){
e.preventDefault();
person();
});
function person(){
jQuery.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
type: 'post',
data: { action: 'data_person', catName: jQuery('#nameCat').val(), catSurnam: jQuery('#surnameCat').val(), catCity: jQuery('#cityCat').val(), catDob: jQuery('#dobCat').val(), catBio: jQuery('#bioCat').val() },
success: function(data) {
jQuery(".modal-body .help-text").html(data);
}
});
}
</script>
<?php }
add_action('wp_ajax_data_person' , 'data_person');
add_action('wp_ajax_nopriv_data_person','data_person');
function data_person(){
$catname = $_POST['catName'];
$surnameCat = $_POST["surnameCat"];
$cityCat = $_POST["cityCat"];
$catDob = $_POST["dobCat"];
$catBio = $_POST["catBio"];
$cat_ID = get_cat_ID( sanitize_title_for_query($catname) );
// Check if category exists
if($cat_ID == 0) {
$my_cat = array(
'cat_name' => $cat_name,
'category_description' => $cat_bio,
'category_nicename' => $cat_slug,
'category_parent' => 0
);
$cat_id = wp_insert_category( $my_cat );
if( ! is_wp_error( $cat_id ) && (int)$cat_id ) {
// NOW, add the metadata...
add_term_meta( $cat_id, '_pagetitle', $surnameCat );
echo json_encode("Category added successfully");
} else {
echo json_encode("That category already exists");
}
}
exit;
}
And the html:
<div class="col-xs-12">
<div class="add-pearson-form memory-form">
<div class="m-form-wrap">
<i class="fa fa-times-circle"></i>
<div class="team_person">
<div class="form-group">
<div class="col-xs-12 col-sm-8 col-sm-offset-2">
<h4 class="text-center text-uppercase">aggiungi una persona</h4>
<input type="text" class="form-control" placeholder="NOME">
<input type="text" class="form-control" placeholder="COGNOME">
<input type="text" class="form-control" placeholder="CITTA">
<input type="text" class="form-control pickdate" placeholder="DATA DI NASCITA">
<textarea class="form-control" id="froala-editor" placeholder=" type ricordo"></textarea>
<div class="text-center">
inserisci persona
</div>
</div>
</div>
</div>
</div>
</div>
</div>
The answer to your question is to use the add_term_meta function.
Don't insert cat_title into the category - the wp_insert_category function doesn't accept / use that argument.
Instead, get the category ID back from wp_insert_category, then use that ID to add the meta value.
See your modified / simplified code below, with comments explaining changes:
// no need to assign variables here, commented out and using originals below
// $cat_name = $catname;
// $cat_sur = $surnameCat;
// $cat_city = $cityCat;
// $cat_dob = $catDob;
// $cat_bio = $catBio;
// $cat_slug = sanitize_title_with_dashes($cat_name);
$my_cat = array(
'cat_name' => $catname,
'category_description' => $catBio,
// this is a _custom meta field_, so doesn't get inserted here...
// 'cat_title' => $cat_sur,
'category_nicename' => sanitize_title_with_dashes($catname),
'category_parent' => 0
);
// get the category ID from the insert
$cat_id = wp_insert_category( $my_cat );
if( ! is_wp_error( $cat_id ) && (int)$cat_id ) {
// NOW, add the metadata...
add_term_meta( $cat_id, '_pagetitle', $surnameCat );
echo json_encode("Category added successfully");
} else {
echo json_encode("That category already exists");
}
I have a function I wrote in my functions.php page for a gallery to display on certain pages. It displays on custom templates, but now I need it to display on index.php Here is the code from my functions.php file:
function min_get_page_gallery( $echo = true) {
global $post;
$show_gallery = get_post_meta($post->ID, 'min_gallery-show', true);
if ( empty($show_gallery) ) {
return;
}
$gallery = get_post_meta($post->ID, 'min_image_advanced', false);
ob_start();
?>
<div class="gallery" id="gallery-<?php echo $post->ID; ?>">
<button class="gallery-move-left"><i class="fa fa-arrow-circle-left" aria-hidden="true"></i></button>
<div class="image_container clearfix">
<?php
$count = count($gallery);
$num = ceil($count / 3);
//$width_container = $num * 100;
//$width_row = 100 / $num;
//echo '<div class="gallery_inner" style="width:' . $width_container . '%;">';
echo '<div class="gallery_inner">';
for ( $i = 0; $i < $count; $i++) {
if ( $i % 3 == 0 ) {
//echo '<div class="row" style="width: ' . $width_row . '%;">';
echo '<div class="row'. (0 == $i ? ' active': ' inactive') .'">';
}
echo '<div class="col-sm-4 img_container' . (0 == $i ? ' active': ' inactive') . '">';
echo wp_get_attachment_image($gallery[$i], 'thumb-gallery');
echo '</div>';
if ( $i % 3 == 2 || ($i+1) == $count) {
echo '</div>';
}
}
echo '</div>';
?>
</div>
<button class="gallery-move-right"><i class="fa fa-arrow-circle-right" aria-hidden="true"></i></button>
</div>
<?php
$return = ob_get_contents();
ob_end_clean();
if ( $echo ) {
echo $return;
} else {
return $return;
}
}
That code works like a charm. Here is where I call it as min_get_page_gallery(); in awards.php where it works flawlessly:
<?php
/* Template Name: Awards Page Template */
get_header(); ?>
<div class="container" id="block-no-sidebar">
<h1><?php the_title(); ?></h1>
<div id="award-list">
<?php echo min_get_awards(); ?>
</div>
<div class="row">
<?php min_get_page_gallery(); ?>
</div>
<?php min_get_page_tabs(); ?>
</div>
<?php get_footer(); ?>
Now finally, I try to add the same function call of min_get_page_gallery(); in my index.php file like this:
<?php
// Silence is golden.
if ( ! defined ( 'ABSPATH' ) ) {
exit;
}
?>
<?php get_header(); ?>
<style class="take-to-head">
#block-main-content-with-sidebar { background: #ffffff; }
</style>
<div class="container" id="block-main-content-with-sidebar">
<div class="row">
<div class="col-sm-8">
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
l('block-' . get_post_type());
endwhile; else:
l('block-none' );
endif;
?>
</div>
<div class="col-sm-4">
<?php l('block-sidebar'); ?>
</div>
</div>
<div class="row">
<?php min_get_page_gallery(); ?>
</div>
</div>
Is there something I'm missing??
Try to describe in more detail, what is wrong with your index.php? Is some output when load input.php, or blank page?
Is correctly defined ABSPATH? If not, your script exit on the beginning.
For more specific awareness of flow through the script, try to write there some echo
E.g.
<div class="row">
<?php echo "Before calling min_get_page_gallery()" ?>
<?php min_get_page_gallery(); ?>
<?php echo "After calling min_get_page_gallery()" ?>
</div>
Then look, if you can see the messages from echo before and after calling the desired function.
Ok, so I had to do some tweaking to get the meta to show in functions.php I added these lines:
$pagemain = is_page();
and then:
if ( $pagemain == is_page( 35393 ) ) {
$meta[] = array(
'id' => 'imageupload',
'post_types' => array( 'page'),
'context' => 'normal',
'priority' => 'high',
'title' => __( 'Image Gallery', 'min' ),
'fields' => array(
array(
'name' => __( 'Show', 'min' ),
'id' => "{$prefix}_gallery-show",
'desc' => __( '', 'meta-box' ),
'type' => 'checkbox',
'clone' => false,
),
array(
'id' => "{$prefix}_image_advanced",
'name' => __( 'Image Advanced', 'min' ),
'type' => 'image_advanced',
// Delete image from Media Library when remove it from post meta?
// Note: it might affect other posts if you use same image for multiple posts
'force_delete' => false,
// Maximum image uploads
//'max_file_uploads' => 2,
),
),
);
}
I am editing the code page of a wordpress post.
Now here is the full page code:
<?php
add_action( 'init', 'create_recipes' );
function create_recipes() {
//$portfolio_translation = get_option(THEME_NAME_S.'_cp_portfolio_slug','portfolio');
$labels = array(
'name' => _x('Recipes', 'Recipe General Name', 'crunchpress'),
'singular_name' => _x('Recipe Item', 'Recipe Singular Name', 'crunchpress'),
'add_new' => _x('Add New', 'Add New Event Name', 'crunchpress'),
'add_new_item' => __('Add New Recipe', 'crunchpress'),
'edit_item' => __('Edit Recipe', 'crunchpress'),
'new_item' => __('New Recipe', 'crunchpress'),
'view_item' => __('View Recipe', 'crunchpress'),
'search_items' => __('Search Recipe', 'crunchpress'),
'not_found' => __('Nothing found', 'crunchpress'),
'not_found_in_trash' => __('Nothing found in Trash', 'crunchpress'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => CP_PATH_URL . '/framework/images/recipe-icon.png',
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
'supports' => array('title','editor','author','thumbnail','excerpt','comments'),
'rewrite' => array('slug' => 'recipes', 'with_front' => false)
);
register_post_type( 'recipes' , $args);
register_taxonomy(
"recipe-category", array("recipes"), array(
"hierarchical" => true,
"label" => "Recipe Categories",
"singular_label" => "Recipe Categories",
"rewrite" => true));
register_taxonomy_for_object_type('recipe-category', 'recipes');
register_taxonomy(
"recipe-tag", array("recipes"), array(
"hierarchical" => false,
"label" => "Recipe Tag",
"singular_label" => "Recipe Tag",
"rewrite" => true));
register_taxonomy_for_object_type('recipe-tag', 'recipes');
}
add_action('add_meta_boxes', 'add_recipes_option');
function add_recipes_option(){
add_meta_box('recipe-option', __('Recipes Options','crunchpress'), 'add_recipe_option_element',
'recipes', 'normal', 'high');
}
function add_recipe_option_element(){
$recipe_price = '';
$recipe_social = '';
$sidebars = '';
$right_sidebar_recipe = '';
$left_sidebar_recipe = '';
$recipe_detail_xml = '';
$select_chef = '';
$recipe_url = '';
foreach($_REQUEST as $keys=>$values){
$$keys = $values;
}
global $post;
$recipe_detail_xml = get_post_meta($post->ID, 'recipe_detail_xml', true);
$ingredients_settings = get_post_meta($post->ID, 'ingredients_settings', true);
$nutrition_settings = get_post_meta($post->ID, 'nutrition_settings', true);
if($recipe_detail_xml <> ''){
$cp_recipe_xml = new DOMDocument ();
$cp_recipe_xml->loadXML ( $recipe_detail_xml );
$recipe_price = find_xml_value($cp_recipe_xml->documentElement,'recipe_price');
$recipe_url = find_xml_value($cp_recipe_xml->documentElement,'recipe_url');
$recipe_social = find_xml_value($cp_recipe_xml->documentElement,'recipe_social');
$sidebars = find_xml_value($cp_recipe_xml->documentElement,'sidebars');
$left_sidebar_recipe = find_xml_value($cp_recipe_xml->documentElement,'left_sidebar_recipe');
$right_sidebar_recipe = find_xml_value($cp_recipe_xml->documentElement,'right_sidebar_recipe');
}
?>
<div class="event_options">
<ul class="recipe_class top-bg">
<li><h2>Recipe Options and Social Sharing</h2></li>
</ul>
<ul class="recipe_class">
<li class="panel-title">
<label for="recipe_social" > <?php _e('SOCIAL NETWORKING', 'crunchpress'); ?> </label>
</li>
<li class="panel-input">
<label for="recipe_social"><div class="checkbox-switch <?php
echo ($recipe_social=='enable' || ($recipe_social=='' && empty($default)))? 'checkbox-switch-on': 'checkbox-switch-off';
?>"></div></label>
<input type="checkbox" name="recipe_social" class="checkbox-switch" value="disable" checked>
<input type="checkbox" name="recipe_social" id="recipe_social" class="checkbox-switch" value="enable" <?php
echo ($recipe_social=='enable' || ($recipe_social=='' && empty($default)))? 'checked': '';
?>>
</li>
<li class="description"><p>Turn On/Off Social Sharing on Event Detail.</p></li>
</ul>
<div class="clear"></div>
<ul class="recipe_class">
<li class="panel-title">
<label for="recipe_price" > <?php _e('RECIPE PRICE', 'crunchpress'); ?> </label>
</li>
<li class="panel-input">
<input type="text" name="recipe_price" id="recipe_price" value="<?php if($recipe_price <> ''){echo $recipe_price;};?>" />
</li>
<li class="description"><p>Please enter your recipe price.</p></li>
</ul>
<div class="clear"></div>
<!--david-->
<ul class="recipe_class">
<li class="panel-title">
<label for="recipe_url" > <?php _e('RECIPE URL', 'crunchpress'); ?> </label>
</li>
<li class="panel-input">
<input type="text" name="recipe_url" id="recipe_url" value="<?php if($recipe_url <> ''){echo $recipe_url;};?>" />
</li>
<li class="description"><p>Please enter your url</p></li>
</ul>
<div class="clear"></div>
<!--david end-->
<?php echo show_sidebar($sidebars,'right_sidebar_recipe','left_sidebar_recipe',$right_sidebar_recipe,$left_sidebar_recipe);?>
<ul class="recipe_class">
<li class="panel-title">
<label><?php _e('Add Ingredients', 'crunchpress'); ?></label>
</li>
<li class="panel-input">
<input type="text" id="add-more-ingre" value="type title here" rel="type title here">
<div id="add-more-ingre" class="add-more-ingre"></div>
</li>
<li class="description"><p>Add Ingredients for this recipe.</p></li>
<div class="clear"></div>
<ul class="nut_table">
<li>
<div>SrNo</div>
<div>Name</div>
<div class="panel-delete-cc"> </div>
</li>
</ul>
<ul id="selected-ingre" class="selected-ingre nut_table_inner">
<li class="default-ingre-item" id="ingre-item">
<div class="ingre-item-counter"></div>
<div class="ingre-item-text"></div>
<div class="panel-delete-ingre"></div>
<input type="hidden" id="ingredients">
</li>
<?php
//Sidebar addition
if($ingredients_settings <> ''){
$ingre_xml = new DOMDocument();
$ingre_xml->loadXML($ingredients_settings);
$counter = 0;
foreach( $ingre_xml->documentElement->childNodes as $ingre_name ){
$counter++;
?>
<li class="ingre-item" id="ingre-item">
<div class="ingre-item-counter"><?php echo $counter;?></div>
<div class="ingre-item-text"><?php echo $ingre_name->nodeValue; ?></div>
<div class="panel-delete-ingre"></div>
<input type="hidden" name="ingredients[]" id="ingredients" value="<?php echo $ingre_name->nodeValue; ?>">
</li>
<?php }
}
?>
</ul>
</ul>
<div class="clear"></div>
<ul class="recipe_class">
<li class="panel-title">
<label> <?php _e('Add Nutrition', 'crunchpress'); ?> </label>
</li>
<li class="panel-input">
<input type="text" id="add-more-nutrition" value="type title here" rel="type title here">
<div id="add-more-nutrition" class="add-more-nutrition"></div>
</li>
<li class="description"><p>Add Nutrition for this recipe.</p></li>
<div class="clear"></div>
<ul class="nut_table">
<li>
<div>SrNo</div>
<div>Name</div>
<div class="panel-delete-cc"> </div>
</li>
</ul>
<br class="clear">
<ul id="selected-nutrition" class="selected-nutrition nut_table_inner">
<li class="default-nutrition-item" id="nutrition-item">
<div class="nut-item-counter"></div>
<div class="nutrition-item-text"></div>
<div class="panel-delete-nutrition"></div>
<input type="hidden" id="nutrition">
</li>
<?php
//Sidebar addition
if($nutrition_settings <> ''){
$ingre_xml = new DOMDocument();
$ingre_xml->loadXML($nutrition_settings);
$counter = 0;
foreach( $ingre_xml->documentElement->childNodes as $ingre_name ){
$counter++;
?>
<li class="nutrition-item" id="nutrition-item">
<div class="nut-item-counter"><?php echo $counter;?></div>
<div class="nutrition-item-text"><?php echo $ingre_name->nodeValue; ?></div>
<div class="panel-delete-nutrition"></div>
<input type="hidden" name="nutrition[]" id="nutrition" value="<?php echo $ingre_name->nodeValue; ?>">
</li>
<?php }
}
?>
</ul>
</ul>
<div class="clear"></div>
<ul class="recipe_class">
<li class="panel-title">
<label for="select_chef"><?php _e('SELECT CHEF', 'crunchpress'); ?></label>
</li>
<li class="panel-input">
<div class="combobox">
<select name="select_chef" id="select_chef">
<option>-- Select Chef --</option>
<?php
foreach(get_title_list_array('teams') as $our_team){?>
<option <?php if($select_chef == $our_team->post_name){echo 'selected';}?> value="<?php echo $our_team->post_name;?>"><?php echo $our_team->post_title?></option>
<?php }?>
</select>
</div>
</li>
<li class="description"><p>Please select Chef of this recipe.</p></li>
</ul>
<div class="clear"></div>
<input type="hidden" name="nutrition_type" value="nutrition">
<div class="clear"></div>
</div>
<div class="clear"></div>
<?php }
add_action('save_post','save_recipe_option_meta');
function save_recipe_option_meta($post_id){
$recipe_social = '';
$sidebars = '';
$right_sidebar_recpie = '';
$left_sidebar_recpie = '';
foreach($_REQUEST as $keys=>$values){
$$keys = $values;
}
if(defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE) return;
if(isset($nutrition_type) AND $nutrition_type == 'nutrition'){
$new_data = '<recipe_detail>';
$new_data = $new_data . create_xml_tag('recipe_price',$recipe_price);
$new_data = $new_data . create_xml_tag('recipe_url',$recipe_url);
$new_data = $new_data . create_xml_tag('recipe_social',$recipe_social);
$new_data = $new_data . create_xml_tag('sidebars',$sidebars);
$new_data = $new_data . create_xml_tag('right_sidebar_recipe',$right_sidebar_recipe);
$new_data = $new_data . create_xml_tag('left_sidebar_recipe',$left_sidebar_recipe);
$new_data = $new_data . '</recipe_detail>';
//Saving Sidebar and Social Sharing Settings as XML
$old_data = get_post_meta($post_id, 'recipe_detail_xml',true);
save_meta_data($post_id, $new_data, $old_data, 'recipe_detail_xml');
$recipe_setting_xml = '<recipe_ingredients>';
if(isset($_POST['ingredients'])){$ingredients = $_POST['ingredients'];
foreach($ingredients as $keys=>$values){
$recipe_setting_xml = $recipe_setting_xml . create_xml_tag('ingredients',$values);
}
}else{$ingredients = '';}
$recipe_setting_xml = $recipe_setting_xml . '</recipe_ingredients>';
//Saving Sidebar and Social Sharing Settings as XML
$old_data_ingre = get_post_meta($post_id, 'ingredients_settings',true);
save_meta_data($post_id, $recipe_setting_xml, $old_data_ingre, 'ingredients_settings');
$nutrition_setting_xml = '<recipe_nutrition>';
if(isset($_POST['nutrition'])){$nutrition = $_POST['nutrition'];
foreach($nutrition as $keys=>$values){
$nutrition_setting_xml = $nutrition_setting_xml . create_xml_tag('nutrition',$values);
}
}else{$nutrition = '';}
$nutrition_setting_xml = $nutrition_setting_xml . '</recipe_nutrition>';
//Saving Sidebar and Social Sharing Settings as XML
$old_data_nut = get_post_meta($post_id, 'nutrition_settings',true);
save_meta_data($post_id, $nutrition_setting_xml, $old_data_nut, 'nutrition_settings');
}
}
//FRONT END RECIPE LAYOUT
$recipe_div_size_num_class = array(
"Full-Image" => array("index"=>"1", "class"=>"sixteen ", "size"=>array(300,110), "size2"=>array(300,110), "size3"=>array(300,110)),
"Small-Thumbnail" => array("index"=>"2", "class"=>"sixteen", "size"=>array(445,175), "size2"=>array(445,175), "size3"=>array(445,175)));
// Print Recipe item
function print_recipe_item($item_xml){
wp_reset_query();
global $paged,$sidebar,$recipe_div_size_num_class,$post,$wp_query,$counter;?>
<!--<script src="<?php echo CP_PATH_URL;?>/frontend/js/jquery-filterable.js" type="text/javascript"></script>-->
<?php
if(empty($paged)){
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
}
//echo '<pre>';print_r($item_xml);die;
//print_r($event_div_size_num_class);
//$item_type = find_xml_value($item_xml, 'recipe-thumbnail-type');
$item_type = 'Full-Image';
// get the item class and size from array
$item_class = $recipe_div_size_num_class[$item_type]['class'];
$item_index = $recipe_div_size_num_class[$item_type]['index'];
$full_content = find_xml_value($item_xml, 'show-full-news-post');
if( $sidebar == "no-sidebar" ){
$item_size = $recipe_div_size_num_class[$item_type]['size'];
}else if ( $sidebar == "left-sidebar" || $sidebar == "right-sidebar" ){
$item_size = $recipe_div_size_num_class[$item_type]['size2'];
}else{
$item_size = $recipe_div_size_num_class[$item_type]['size3'];
}
// get the blog meta value
$header = find_xml_value($item_xml, 'header');
$num_fetch = find_xml_value($item_xml, 'num-fetch');
$num_excerpt = find_xml_value($item_xml, 'num-excerpt');
$category = find_xml_value($item_xml, 'category');
$show_filterable = find_xml_value($item_xml, 'show-filterable');
$category_name = '';
$category = ( $category == 'All' )? '': $category;
if( !empty($category) ){
$category_term = get_term_by( 'name', $category , 'recipe-category');
$category = $category_term->term_id;
$category_name = $category_term->name;
}
?>
<h2 class="heading"><?php echo $header;?></h2>
<?php
//Filterable Recipe Script start
if($show_filterable == 'Yes'){?>
<script>
jQuery(window).load(function() {
var filter_container = jQuery('#portfolio-item-holder<?php echo $counter?>');
filter_container.children().css('position','absolute');
filter_container.masonry({
singleMode: true,
itemSelector: '.portfolio-item:not(.hide)',
animate: true,
animationOptions:{ duration: 800, queue: false }
});
jQuery(window).resize(function(){
var temp_width = filter_container.children().filter(':first').width() + 20;
filter_container.masonry({
columnWidth: temp_width,
singleMode: true,
itemSelector: '.portfolio-item:not(.hide)',
animate: true,
animationOptions:{ duration: 800, queue: false }
});
});
jQuery('ul#portfolio-item-filter<?php echo $counter?> a').click(function(e){
jQuery(this).addClass("active");
jQuery(this).parents("li").siblings().children("a").removeClass("active");
e.preventDefault();
var select_filter = jQuery(this).attr('data-value');
if( select_filter == "All" || jQuery(this).parent().index() == 0 ){
filter_container.children().each(function(){
if( jQuery(this).hasClass('hide') ){
jQuery(this).removeClass('hide');
jQuery(this).fadeIn();
}
});
}else{
filter_container.children().not('.' + select_filter).each(function(){
if( !jQuery(this).hasClass('hide') ){
jQuery(this).addClass('hide');
jQuery(this).fadeOut();
}
});
filter_container.children('.' + select_filter).each(function(){
if( jQuery(this).hasClass('hide') ){
jQuery(this).removeClass('hide');
jQuery(this).fadeIn();
}
});
}
filter_container.masonry();
});
});
</script>
<ul id="portfolio-item-filter<?php echo $counter?>" class="category-list">
<li><a data-value="all" class="gdl-button active" href="#">All</a></li>
<?php
$categories = get_categories( array('child_of' => $category, 'taxonomy' => 'recipe-category', 'hide_empty' => 0) );
//$categories = get_the_terms( $post->ID, 'recipe-category' );
if($categories <> ""){
foreach($categories as $values){?>
<li><a data-value="<?php echo $values->term_id;?>" class="gdl-button" href="#"><?php echo $values->name;?></a></li>
<?php
}
}?>
<div class="clear"></div>
</ul>
<?php }else{?>
<h2 class="heading"><?php echo $category_name; ?></h2>
<?php }?>
<ul class="lightbox gallery_filterable" id="portfolio-item-holder<?php echo $counter?>">
<?php
$category = find_xml_value($item_xml, 'category');
$category = ( $category == 'All' )? '': $category;
if( !empty($category) ){
$category_term = get_term_by( 'name', $category , 'recipe-category');
$category = $category_term->slug;
}
if($show_filterable == 'Yes'){
query_posts(array(
'posts_per_page' => -1,
'post_type' => 'recipes',
'recipe-category' => $category,
'post_status' => 'publish',
'order' => 'ASC',
));
}else{
query_posts(array(
'posts_per_page' => $num_fetch,
'paged' => $paged,
'post_type' => 'recipes',
'recipe-category' => $category,
'post_status' => 'publish',
'order' => 'ASC',
));
}
while( have_posts() ){
global $post;
the_post(); ?>
<li class="all portfolio-item item alpha
<?php
$categories = get_the_terms( $post->ID, 'recipe-category' );
if($categories <> ''){
foreach ( $categories as $category ) {
echo $category->term_id." ";
}
}
?>">
<h3 class="heading">
<a href="<?php echo get_permalink();?>">
<?php
echo substr($post->post_title, 0, 20);
if ( strlen($post->post_title) > 20 ) echo "...";
?>
</a>
</h3>
<a href="<?php echo get_permalink();?>" class="caption">
<?php echo get_the_post_thumbnail($post->ID, $item_size);?>
<span class="hover-effect big zoom"></span>
</a>
<!--david-->
<article class="menu-det">
<p><?php echo strip_tags(mb_substr(get_the_content(),0,$num_excerpt));?> <a class="c-link" href="<?php echo $recipe_url;?>"><?php _e('Read More...', 'crunchpress'); ?></a></p>
</article>
</li>
<?php }//End While?>
</ul>
<div class="clear"></div>
<?php
if( find_xml_value($item_xml, "pagination") == "Yes" AND $show_filterable == 'No'){
pagination();
}
}
?>
Now, at the bottom of this page above, you will see a readmore link with the following content:
<article class="menu-det">
<p><?php echo strip_tags(mb_substr(get_the_content(),0,$num_excerpt));?> <a class="c-link" href="<?php echo $recipe_url;?>"><?php _e('Read M...', 'crunchpress'); ?></a></p>
</article>
Now the part giving me issues, is this one:
<?php echo $recipe_url;?>
So I basically only registered a new variable: $recipe_url;, and I replaced the original link href value of:
href="<?php echo get_permalink()?>"
with my new variable:
href="<?php echo $recipe_url;?>"
Now the url is empty on the webpage, even though a value is set. I even used some of the original variables included in the theme:
href="<?php echo $recipe_price;?>"
but it also does not populate a any url or href value..
Why is this? Am I calling it wrong?
Thanks
I don't have enough rep to add a comment to the question, but you don't appear to have added a closing brace to the add_recipe_option_element() method either.