i have a problem, in first this is my code
$page_id = get_queried_object_id();
$post = get_post($page_id);
$filter_args = array(
'tax_query'=>array(),
'meta_query'=>array()
);
$posts_per_page = 5;
$args = array(
'posts_per_page' => $posts_per_page,
'post_type' => 'property',
'orderby' => 'date'
);
$args = array_merge($args, $filter_args);
$query = new WP_Query( $args );
$items = array();
if(count($query->posts) > 0){
$items = $query->posts;
}
$acf_fields = get_acf_fields(array('general_property_fields', 'property_price'));
foreach($items as $k=>$v){
$items[$k]->acf = get_acf_data($v->ID, $acf_fields);
$items[$k]->pc = sb_get_price($v->ID);
}
The get_acf_fields is a personal function, not worry in this question about that.
And this is my loop for get the values i want.
<?php foreach ($items as $v) {
$status = $v->acf['c_status'];
$status_name = get_term_by('id', $status, 'type');
?>
<?php if ($status_name) { ?>
<div class="sb-sidebar-featured-type">
<?php
$title_status = $status_name->name;
$status = explode(' ', $title_status);
?>
<div class="sidebar-featured-transaction"><?=($status_name) ? $status[0] : '';?></div>
</div>
<?php } ?>
All work fine, but the status give me all values from the taxonomy with name status, for example if i obtain "sold", "discount", "offer", i want to exlude the results with "sold" in the taxonomy but i dont know how make that, thanks :D
Will you please try like this:
<?php if ($status_name != 'sold') { ?>
<div class="sb-sidebar-featured-type">
<?php
$title_status = $status_name->name;
$status = explode(' ', $title_status);
?>
<div class="sidebar-featured-transaction"><?=($status_name) ? $status[0] : '';?></div>
</div>
<?php } ?>
Here is the code working for somelse
<?php foreach ($items as $v) {
$tax_type = $v->acf['c_type'];
$status = $v->acf['c_status'];
$type_name = get_term_by('id', $tax_type, 'type');
$status_name = get_term_by('id', $status, 'type');
if ($status_name) {
$check_status = trim($status_name->slug);
}
if ($check_status != 'sold' && $check_status != 'vendido') {
?>
<div class="sidebar-featured-cont">
<div class="sidebar-featured">
<a class="sidebar-featured-image" href="<?=get_permalink($v->ID)?>">
<img src="<?=$v->acf['c_gallery'][0]['sizes']['property-listing']?>" alt="" />
<?php if ($status_name) { ?>
<div class="sb-sidebar-featured-type">
<?php
$title_status = $status_name->name;
$status = explode(' ', $title_status);
?>
<div class="sidebar-featured-transaction"><?=($status_name) ? $status[0] : '';?></div>
</div>
<?php } ?>
</a>
<div class="sidebar-featured-title"><?=$v->post_title?></div>
<div class="sidebar-featured-price">$ <?=$v->pc?></div>
<div class="clearfix"></div>
</div>
</div>
<?php } ?>
<?php } ?>
Related
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>
i've created a colophon for my website in which i post all the logos of the different sponsors i have. I add all the sponsors via custom post type. i also added a specific custom taxonomy to distinguish between the different typologies of sponsorships.
I use this code in the footer.php to display them:
<?php $terms = get_terms('sponsor_tipology');
$count = count( $terms );
if ( $count > 0 ) {
foreach ( $terms as $term ) { ?>
<div class="col-xs-12 <?php echo $term->slug ;?>">
<h3><?php echo $term->name;?></h3>
<?php $arg = array (
'post_type' => 'colophone',
'post_per_page' => -1,
'sponsor_edition' => 'current',
'sponsor_tipology' => $term->slug,
);
$pesca_post = new WP_Query ($arg);
$quanti_post = $pesca_post->post_count;
if(have_posts()){
while ($pesca_post->have_posts()) : $pesca_post->the_post();
$featured = get_the_post_thumbnail_url(get_the_ID(),'large');
if ($quanti_post == 5){
$classe_bootstrap = 15;
}elseif ($quanti_post > 5){
$classe_bootstrap = "2 text-center";
}elseif($quanti_post < 5){
$classe_bootstrap = 12/$quanti_post;
}
echo '<div class="col-md-' . $classe_bootstrap . '">';
if (isset($featured)){
$img = $featured;
}else{
$img = get_template_directory_uri() . '/img/placeholder.png';
} ?>
<a href="<?php echo esc_attr(get_permalink($msd_settings['partner_page'])); ?>" title="<?php echo get_the_title($post->ID);?>" >
<div class="col-xs-12" style="background-image:url(<?php echo esc_url($img); ?>); height:100px;background-size:contain;background-repeat:no-repeat;background-position:center center;"></div>
</a>
<?php echo '</div>';
endwhile;
}?>
</div>
<?php }
}?>
my problem is that this code is completely working just on some pages, on other it shows the contents avoiding the ones belonging to the first term, no matter which it will be.
I have noticed that it works in pagaes where i use other queries.
What am i doing wrong?
i changed it in this way and now it's working!
$terms = get_terms('sponsor_tipology');
$count = count( $terms );
if ( $count > 0 ) {
foreach ( $terms as $term ) { //per ogni termine presente
$nome = $term->slug;?>
<div class="col-xs-12 <?php echo $term->slug ;?>">
<h3><?php echo $term->name;?></h3>
<?php $arg = array (
'post_type' => 'colophone',
'post_per_page' => -1,
'sponsor_edition' => 'current',
'sponsor_tipology' => $nome,
);
$elementi = get_posts($arg);
$quanti_post = count( $elementi );
if ($quanti_post == 5){
$classe_bootstrap = 15;
}
elseif ($quanti_post > 5){
$classe_bootstrap = "2 text-center";
}
elseif($quanti_post < 5){
$classe_bootstrap = 12/$quanti_post;
}
foreach($elementi as $elemento){
$featured = get_the_post_thumbnail_url($elemento->ID,'large');
if (isset($featured)){
$img = $featured;
}
else{
$img = get_template_directory_uri() . '/img/placeholder.png';
} ?>
<div class="col-md-<?php echo $classe_bootstrap; ?>">
<a href="<?php echo esc_attr(get_permalink($msd_settings['partner_page'])); ?>" title="<?php echo get_the_title($elemento->ID);?>" >
<div class="col-xs-12" style="background-image:url(<?php echo esc_url($img); ?>); height:100px;background-size:contain;background-repeat:no-repeat;background-position:center center;"></div>
</a>
</div>
<?php }?>
</div>
<?php }
}?>
I have a function called getNews().
I call getNews() like this:
<div class="wrapper" id="blog">
<div class="blogPosts">
<?PHP getNews($postPerPage, 0, $theme_link, $pageNum); ?>
</div>
</div>
The function works until it tries to get the article text from wordpress using get_post_field().
function getNews($numPosts, $offset, $theme_link, $pageNum) {
$offset = $numPosts * $pageNum;
$recent_args = array('numberposts' => $numPosts, 'offset' => $offset,);
$articles = wp_get_recent_posts($recent_args);
foreach($articles as $article){
$article_id = $article['ID'];
...
echo $article_text = get_post_field('post_content', $article_id);
...
}
}
When I run this, I get the error saying Fatal error: Cannot redeclare getNews() (previously declared in /homepages/30/d545089862/htdocs/VintageTroubleMusic/wp-content/plugins/enhanced-text-widget/enhanced-text-widget.php(57)
For some reason, it's running my loop twice.
Any advice?
EDIT
I'm including the full code here: This is written inside of an "Enhanced Text widget" inside of a page.
<?PHP
$theme_link = "/wp-content/themes/thestory-child/";
$pageNum = $_GET['pa'];
$postPerPage = 27;
$qry_numPosts = mysql_query("SELECT * FROM Ykcfdlqhposts WHERE post_status = 'publish' AND post_type = 'post'") or die(mysql_error());
$numPosts = mysql_num_rows($qry_numPosts);
$numPages = ceil($numPosts/$postPerPage) . " pages";
if(!$pageNum){
$pageNum = 0;
}
?>
<!-- START OF THE BODY HERE -->
<h3 class="widget-title" style="float:left;">Headlines</h3>
<div class="wrapper" id="paginate1">
<?PHP paginate($numPosts, $numPages); ?>
</div>
<div class="wrapper" id="blog">
<div class="blogPosts">
<?PHP getNews($postPerPage, 0, $theme_link, $pageNum); ?>
</div>
</div>
<div class="wrapper" id="paginate2">
<?PHP paginate($numPosts, $numPages); ?>
</div>
And inside of the functions.php page
function getNews($numPosts, $offset, $theme_link, $pageNum) {
$offset = $numPosts * $pageNum;
$recent_args = array('numberposts' => $numPosts, 'offset' => $offset,);
$articles = wp_get_recent_posts($recent_args);
foreach($articles as $article){
$article_id = $article['ID'];
$article_link = get_permalink($article_id);
$article_length = 350;
$article_background = get_the_post_thumbnail($article_id);
$article_title = get_post_meta( $article_id, 'short_title', true );
$article_text = "test";
$article_text = get_post_field('post_content', $article_id);
//$article_text = get_post_field('post_content', $article_id);
//$article_text = strip_tags($article_text);
//$article_text_length = strlen($article_text);
/*
if($article_text_length >= $article_length) {
$article_text_pos = strpos($article_text, " ", $article_length);
$article_text = substr($article_text, 0, $article_text_pos)."... ";
}
*/
?>
<div class="article">
<?PHP //Get the article image
if (!$article_background) {
$rand = rand(1, 5);
$img = $theme_link . "images/img" . $rand . ".jpg";
} else {
$img = explode('src="', $article_background);
$img = explode(".jpg", $img[1]);
$img = $img[0] . ".jpg";
}?>
<a href="<?= $article_link; ?>">
<div class="article__image" style="background-image: url('<?= $img; ?>');"></div>
<div class="article__title"><?= $article_title; ?></div>
</a>
<div class="article__details">
<div class="article-text">
<?= $article_text; ?>
</div>
READ MORE
</div>
</div>
<? }
}
function paginate($numPosts, $numPages) {
?>
<div class="page">
<span>Page:</span><?PHP
$i = 0;
while($i < $numPages){
$i++;
if($i == $pageNum){
echo '<span style="background-color:transparent; text-decoration:underline; color:white; cursor:default;">'.$i.'</span>';
} else {
echo "<a href='?pa=".$i."'><span>".$i."</span></a>";
}
}
?>
</div>
<?
}
I'm thinking there is an easier way to write this code, but not sure on what approach to take. Basically, I want to check if each variable exists, and if so - add the appropriate markup to the page.
Any suggestions would be great.
<?php
$words = get_field('words');
$photography = get_field('photography');
$architect = get_field('architect');
?>
<div class="panel">
<?php if( $words ): ?>
<div>
<p><span>Words</span><span><?php echo $words;?></span></p>
</div>
<?php endif ;?>
<?php if( $photography ): ?>
<div>
<p><span>Photography</span><span><?php echo $photography;?></span></p>
</div>
<?php endif; ?>
<?php if( $architect ): ?>
<div>
<p><span>Architect</span><span><?php echo $architect;?></span></p>
</div>
<?php endif; ?>
</div>
You can use array & loop -
<?php
$fields = array();
$fields['words'] = get_field('words');
$fields['photography'] = get_field('photography');
$fields['architect'] = get_field('architect');
?>
<div class="panel">
<?php foreach($fields as $key => $value):
if($value)
?>
<div>
<p><span><?php echo ucwords($key);?></span><span><?php echo $value;?></span></p>
</div>
<?php
endif;
endforeach;?>
</div>
Create a field array with their appropriate label if you want to have your own labels.
<div class="panel">
<?php
$fields = array (
'words' => 'Words',
'photography' => 'Photography',
'architect' => 'Architect'
);
foreach ( $fields as $field => $label ) {
$value = get_field ( $field );
if (!empty($value)) {
echo '<div>
<p><span>' . $label . '</span><span>' . $value . '</span></p>
</div>';
}
}
?>
</div>
<?php
$required_fields = array("words","photography","architect");
$data = array();
foreach($required_fields as $field)
{
$data[$field] = get_field($field);
}
?>
<div class="panel">
<?php foreach($data as $data_field=>$data_value):
if($data_value)
?>
<div>
<p><span><?=$data_field?></span><span><?=$data_value?></span></p>
</div>
<?php
endif;
endforeach ;?>
</div>
You can create a function like this and then iterate the data that it returns to output your content
<?php
//define a function to fetch data in specific fields
function fetch_data($keys=array()){
$data = array();
foreach($keys as $key){
$val = get_field($key);
if(!empty($val)){
$data[$key] = $val;
}
}
return $data;
}
//now you can easily add or change your fields
$data = fetch_data(array('words','photography','architect'));
?>
<div class="panel">
<?php
foreach($data as $field){
if(isset($data[$field])){
$val = $data[$field];
?>
<div>
<p><span><?php echo ucfirst($field); ?></span><span><?php echo $val; ?></span></p>
</div>
<?php
}
}
?>
My map shows results from posts, but only old ones. Why aren't new ones showing up? I hired a coder from India but he is hiding now. (I already paid him because I didn't anticipate this bug.)
At the bottom of the map, it says: Total Geocoded Ads: 602. This is not true. There are now 608 published posts. So why aren't new ones being found?
Also, why aren't they being presented in order of post_date?
add_action('wp_ajax_query_total', 'query_total');
add_action('wp_ajax_nopriv_query_total', 'query_total');
if (defined('MULTISITE') && (MULTISITE))
{
if (!defined('TT'))
define('TT', plugins_url('/geo-ads/timthumb_wpmu.php'));
}
else
{
if (!defined('TT'))
define('TT', plugins_url('/geo-ads/timthumb.php'));
}
function query_total()
{
global $wpdb;
$table = $wpdb->prefix.'cp_ad_geocodes';
$q = "SELECT COUNT(*) FROM $table t LEFT JOIN $wpdb->posts p ON (p.ID = t.post_id) WHERE p.post_status = 'publish'";
$c = $wpdb->get_var($q);
echo $c;
die();
}
function query_geo_ads()
{
if ($_GET['range'] == 'true') {
query_geo_ads_refresh();
}
else {
global $wpdb;
$table = $wpdb->prefix.'cp_ad_geocodes';
$querystr = "SELECT t.post_id, t.category, t.lat, t.lng, p.post_title, p.post_content, m.meta_value as price, CONCAT(wpo_su.option_value, REPLACE( REPLACE( REPLACE( REPLACE(wpo.option_value,'%year%',date_format(p.post_date,'%Y')) ,'%monthnum%',date_format(p.post_date,'%m')) ,'%day%',date_format(p.post_date,'%d')) ,'%postname%',p.post_name ) ) as permalink
FROM $table t LEFT JOIN $wpdb->posts p ON (p.ID = t.post_id)
INNER JOIN $wpdb->options wpo ON wpo.option_name='permalink_structure'
INNER JOIN $wpdb->options wpo_su ON wpo_su.option_name='siteurl'
LEFT JOIN $wpdb->postmeta m ON (m.meta_key = 'cp_price') AND (m.post_id = p.ID)
WHERE p.post_status = 'publish'
AND p.post_type = 'ad_listing' ";
$ads = $wpdb->get_results($querystr);
$expires = 50000;
$cache_time = mktime();
header("Cache-Control: max-age:" . $expires . ", must-revalidate");
header("Expires: " . gmdate("D, d M Y H:i:s",$cache_time+$expires) . " GMT");
echo json_encode($ads);
die();
}
}
function get_image_url()
{ $post_id = intval($_POST['id']);
$attachment = get_posts(array('post_type' => 'attachment','post_status' => 'publish','order' => 'ASC','orderby' => 'post_date','post_mime_type' => 'image','post_parent' => $post_id));
$height = 100;
$width = 100;
$url = TT.'?src='.wp_get_attachment_url($attachment[0]->ID, false).'&h='.$height.'&w='.$width;
if ($attachment)
echo $url;
die();
}
function query_geo_ads_refresh() {
?>
<div class="undertab"><span class="big">Classified Ads / <strong><span class="colour">Just Listed</span></strong></span></div>
<?php
global $wpdb,$wp_query, $post;
$exclude_categories = $_REQUEST['exclude_categories'];
$term_id = $_REQUEST['term_id'];
$term_slug = $_REQUEST['term_slug'];
$taxonomy_name = $_REQUEST['taxonomy_name'];
$northeast_lng = $_REQUEST['northeast_lng'];
$northeast_lat = $_REQUEST['northeast_lat'];
$southwest_lng = $_REQUEST['southwest_lng'];
$southwest_lat = $_REQUEST['southwest_lat'];
if(!empty($exclude_categories)) {
$exclude_categories = explode(';', $exclude_categories);
}
if(!$term_id) // this means root
//$term_categories = get_terms( 'ad_cat', 'orderby=count&hide_empty=0' );
$term_categories = get_terms( 'ad_cat', 'order=DESC','orderby=post_date' );
else {
$current_term = get_term_by( 'slug', $term_slug, $taxonomy_name );
$term_categories = get_terms( $taxonomy_name, 'order=DESC','orderby=post_date' );
if(empty($term_categories))
$term_categories[] = $current_term;
}
foreach ($term_categories as $catinfo_obj)
{
$term_id = $catinfo_obj->term_id;
$arrsrch = array("'");
$arrrep = array('');
$name = htmlspecialchars_decode($catinfo_obj->name);
$name = strtolower(str_replace($arrsrch,$arrrep,$name));
if(!empty($exclude_categories)) {
if(in_array(strtolower($name), $exclude_categories))
continue;
}
$subterm_ids = get_term_children( $term_id, 'ad_cat' );
$subterm_ids[] = $term_id;
$term_ids = implode(',', $subterm_ids);
if($term_id)
{
$my_post_type = "'ad_listing'";
$sql = "select * from $wpdb->posts p where p.post_type in ($my_post_type) and p.post_status in ('publish') and p.ID in (select tr.object_id from $wpdb->term_relationships tr join $wpdb->term_taxonomy t on t.term_taxonomy_id=tr.term_taxonomy_id where t.term_id in ($term_ids) )";
$postinfo = $wpdb->get_results($sql);
$data_arr = array();
$geo_codes = array();
if($postinfo)
{
$srcharr = array("'");
$replarr = array("\'");
foreach($postinfo as $postinfo_obj)
{
$ID = $postinfo_obj->ID;
$title = str_replace($srcharr,$replarr,($postinfo_obj->post_title));
$plink = get_permalink($postinfo_obj->ID);
$geocode = cp_get_geocode($ID);
$lat = $geocode['lat'];
$lng = $geocode['lng'];
// check current post geo place is within map coord area
if($lat > $northeast_lat || $lat < $southwest_lat)
continue;
if($northeast_lng > $southwest_lng) {
if($lng > $northeast_lng || $lng < $southwest_lng)
continue;
} else {
if($lng > 0 && $lng < $southwest_lng)
continue;
if($lng < 0 && $lng > $northeast_lng)
continue;
}
$address = get_post_meta($ID,'cp_address_line',true);
if(!empty($address))
$address = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_address_line',true)));
else {
$street = get_post_meta($ID,'cp_street',true);
$city = get_post_meta($ID,'cp_city',true);
$state = get_post_meta($ID,'cp_state',true);
$country = get_post_meta($ID,'cp_country',true);
if(!empty($street))
$address .= $street . ', ';
if(!empty($city))
$address .= $city . ', ';
if(!empty($state))
$address .= $state . ', ';
if(!empty($country))
$address .= $country . ', ';
$address = trim($address);
$address = substr($address, 0, strlen($address)-1);
$address = str_replace($srcharr,$replarr,$address);
}
$phone = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_phone',true)));
$email = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_email',true)));
$author = get_userdata($postinfo_obj->post_author);
$category = get_the_category($postinfo_obj->ID);
if($postinfo_obj->post_type == 'ad_listing') {
$timing = date('M d, Y',strtotime(get_post_meta($ID,'cp_start_date',true))).' to '.date('M d, Y',strtotime(get_post_meta($ID,'cp_end_date',true)));
} else {
$timing = date('M d, Y',strtotime(get_post_meta($ID,'st_date',true))).' to '.date('M d, Y',strtotime(get_post_meta($ID,'end_date',true))).'<br />'.get_post_meta($ID,'st_time',true).' to '.get_post_meta($ID,'end_time',true);
}
?>
<?php appthemes_before_post(); ?>
<div class="post-block-out">
<div class="post-block">
<div class="post-left">
<?php if ( get_option('cp_ad_images') == 'yes' ) cp_ad_loop_thumbnail($ID); ?>
</div>
<div class="<?php if ( get_option('cp_ad_images') == 'yes' ) echo 'post-right'; else echo 'post-right-no-img'; ?> <?php echo get_option('cp_ad_right_class'); ?>">
<!-- <h3><?php if ( mb_strlen( $title ) >= 75 ) echo mb_substr( $title, 0, 75 ).'...'; else echo $title; ?></h3>
<div class="clr"></div>
<p class="post-meta">
<span class="folder">
<a href="/ad-category/<?php echo $catinfo_obj->slug; ?>/">
<?php echo $name; ?>
</a>
</span> |
<span class="owner">
<a href="/author/<?php echo $author->user_nicename; ?>">
<?php echo $author->display_name; ?>
</a>
</span> |
<span class="clock"><span><?php echo $timing; ?></span></span>
</p>-->
</div>
<div class="clr"></div>
</div><!-- /post-block -->
</div><!-- /post-block-out -->
<?php
}
}
}
}
die();
}
?>
This is the index.php home page file. This is how the home page appears:
<?php get_header(); ?>
<div class="content_botbg">
<div class="content_res">
<?php // Comment the default CP Slider
// if ( file_exists(STYLESHEETPATH . '/featured.php') )
// include_once(STYLESHEETPATH . '/featured.php');
// else
// include_once(TEMPLATEPATH . '/featured.php');
?>
<!-- left block -->
<!--<div class="content_left">-->
<?php if ( get_option('cp_home_layout') == 'directory' ) : ?>
<div class="shadowblock_out">
<div class="shadowblock">
<h2 class="dotted"><?php _e('Ad Categories','appthemes')?></h2>
<div id="directory" class="directory twoCol">
<?php echo cp_create_categories_list( 'dir' ); ?>
<div class="clr"></div>
</div><!--/directory-->
</div><!-- /shadowblock -->
</div><!-- /shadowblock_out -->
<?php endif; ?>
<div class="tabcontrol">
<ul class="tabnavig">
<li><span class="big"><?php _e('Just Listed','appthemes')?></span></li>
<li><span class="big"><?php _e('Most Popular','appthemes')?></span></li>
<li><span class="big"><?php _e('Random','appthemes')?></span></li>
</ul>
<?php remove_action( 'appthemes_after_endwhile', 'cp_do_pagination' ); ?>
<?php $post_type_url = get_bloginfo('url').'/'.get_option('cp_post_type_permalink').'/'; ?>
<!-- tab 1 -->
<div id="block1">
<div class="clr"></div>
<div class="undertab"><span class="big"><?php _e('Classified Ads','appthemes') ?> / <strong><span class="colour"><?php _e('Just Listed','appthemes') ?></span></strong></span></div>
<?php
// show all ads but make sure the sticky featured ads don't show up first
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
query_posts( array('post_type' => APP_POST_TYPE, 'ignore_sticky_posts' => 1, 'paged' => $paged) );
global $wp_query;
$total_pages = max( 1, absint( $wp_query->max_num_pages ) );
?>
<?php //get_template_part( 'loop', 'ad_listing' ); ?>
<?php
if( $total_pages > 1 ){ ?>
<div class="paging"> <?php _e( 'View More Ads', 'appthemes' ); ?> </div>
<?php } ?>
</div><!-- /block1 -->
<!-- tab 2 -->
<div id="block2">
<div class="clr"></div>
<div class="undertab"><span class="big"><?php _e('Classified Ads','appthemes') ?> / <strong><span class="colour"><?php _e('Most Popular','appthemes') ?></span></strong></span></div>
<?php get_template_part( 'loop', 'featured' ); ?>
<?php global $cp_has_next_page; ?>
<?php if($cp_has_next_page){ ?>
<div class="paging"> <?php _e( 'View More Ads', 'appthemes' ); ?> </div>
<?php } ?>
<?php wp_reset_query(); ?>
</div><!-- /block2 -->
<!-- tab 3 -->
<div id="block3">
<div class="clr"></div>
<div class="undertab"><span class="big"><?php _e('Classified Ads','appthemes') ?> / <strong><span class="colour"><?php _e('Random','appthemes') ?></span></strong></span></div>
<?php
// show all random ads but make sure the sticky featured ads don't show up first
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
query_posts( array('post_type' => APP_POST_TYPE, 'ignore_sticky_posts' => 1, 'paged' => $paged, 'orderby' => 'rand') );
global $wp_query;
$total_pages = max( 1, absint( $wp_query->max_num_pages ) );
?>
<?php get_template_part( 'loop', 'ad_listing' ); ?>
<?php
if( $total_pages > 1 ){ ?>
<div class="paging"> <?php _e( 'View More Ads', 'appthemes' ); ?> </div>
<?php } ?>
</div><!-- /block3 -->
</div><!-- /tabcontrol -->
</div><!-- /content_left -->
<?php //get_sidebar(); ?>
<div class="clr"></div>
</div><!-- /content_res -->
</div><!-- /content_botbg -->