How to Display Wordpress Posts by Custom Field - custom-fields

I am trying to create a page that displays all my wordpress posts that contain a certain custom field. I assumed that the best way to do this is to create a "custom page template" and use a new WP_query to list the posts in question. I created a new "page" and applied the new "page template" with my new WP_query, however no posts show up on the page. Can anyone tell me why this custom page template does not correctly list the posts in question? Any help is much appreciated!
<?php
/**
* Template Name: Recommended Incentives
*
* #package WordPress
* #subpackage Twenty_Fourteen
* #since Twenty Fourteen 1.0
*/
get_header(); ?>
<div id="main-content" class="main-content">
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
// args
$args = array(
'meta_key' => 'Incentive ID',
'meta_value' => '20'
);
// get results
$the_query = new WP_Query( $args );
// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<?php the_title(); ?>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
</div><!-- #content -->
</div><!-- #primary -->
</div><!-- #main-content -->
<?php
get_sidebar();
get_footer();

Thanks Andy,
My code worked when I specified the post type in the $args variable. The code I used is
'meta_key' => 'Incentive ID',
'meta_value' => array(20,21),
'orderby' => 'meta_value_num',
'order' => 'ASC',
'post_type' => 'incentives'

Related

How to i get Events previous and next Event in contao detail page and list page ? f.e < Previous Event | Current Event ( id - 4) | Next Event >

How to i get Events previous and next Event in contao detail page and list page ? f.e < Previous Event | Current Event ( id - 4) | Next Event
Blockquote
There is no extension for Contao 3 that I know of. However, you could do the following.
Insert the following PHP code at the top of your event_full template:
<?php
$this->getEventUrl = function($objEvent)
{
global $objPage;
return \Controller::generateFrontendUrl($objPage->row(), '/' . $objEvent->alias, null, true );
};
$objNextEvent = \CalendarEventsModel::findOneBy(
array("startDate > ?", "published = '1'", "pid = ?"),
array($this->startDate, $this->pid),
array('order' => 'startDate ASC'));
$objPreviousEvent = \CalendarEventsModel::findOneBy(
array("startDate < ?", "published = '1'", "pid = ?"),
array($this->startDate, $this->pid),
array('order' => 'startDate DESC'));
?>
This will try to fetch the previous and next event in the most simple way.
Insert the following somewhere in your event_full template (e.g. before the last closing </div>:
<?php if ($objPreviousEvent || $objNextEvent): ?>
<div class="pagination">
<?php if ($objPreviousEvent): ?>
<div class="prev">
<a href="<?= $this->getEventUrl( $objPreviousEvent ) ?>" title="<?= $objPreviousEvent->title ?>">
« <?= $objPreviousEvent->title ?>
</a>
</div>
<?php endif ?>
<?php if ($objNextEvent): ?>
<div class="next">
<a href="<?= $this->getEventUrl( $objNextEvent ) ?>" title="<?= $objNextEvent->title ?>">
<?= $objNextEvent->title ?> »
</a>
</div>
<?php endif ?>
</div>
<?php endif ?>
This will echo the URLs to the previous and next events within some HTML code.
There are some drawbacks:
the code above does not consider the start and end fields
this will only show the previous and next event of the same calendar (otherwise the target URL might be wrong)
this will only work with an enabled auto_item parameter
Update: I have created a Github Gist here: https://gist.github.com/fritzmg/aa4632be2231d77e7d6ec0e5e0a854ae

Magento Checkout Methods list

Is there a way to see the methods lists that is being called in the shopping cart view.
<ul class="checkout-types">
<?php foreach ($this->getMethods('methods') as $method): ?>
<?php if ($methodHtml = $this->getMethodHtml($method)): ?>
<li><?php echo $methodHtml; ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
This code is in the views anywhere the "Proceed to Checkout" button shows up but my Paypal Express button isn't in the list. I can trace it back to the Block abstract but then the code looses me (ie what calls setChild to make 'methods' a child and to give it a block?).

How to adapt this wordpress loop query code to include pagination?

I have sourced the below code to query my posts in Wordpress and all works as intended.
I'd like to add pagination to this now. I don't want to alter the code too much now that I know it works, can anyone advise on the best way to adapt this to include the pagination?
I would like it to show a maximum of 18 posts per page and have next and prev links to other pages if they exist. This code is being used in custom category templates, but I have also setup a static page setup under the reading settings and the display of main posts uses home.php, I'd like to use the same or similar loop code to also paginate that. Any help is appreciated. Here is the code:
<div id="Items">
<ul>
<?php
// Grid sorted alphabetically
if (is_category('categoryName'))
{
$args = array( 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC', 'category' => 41 );
$categoryNameposts = get_posts( $args );
}
foreach( $categoryNameposts as $post ) : setup_postdata($post);
?>
<li><?php get_template_part( 'content', get_post_format() ); ?></li>
<?php endforeach; ?>
</ul>
</div><!-- #ItemsEnd -->
You should let wordpress know how much post you want to show per page in the query_posts. Replace your $args with these two lines:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'posts_per_page' => 18, 'paged' => $paged, 'orderby'=> 'title', 'order' => 'ASC', 'category' => 41 );
Now to show Next-Previous link:
<div class="paginationClass">
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
</div>
Also in is_category function, use categorySlug, instead of categoryName.

putting jquery buttons in clistview widget in yii

I am trying to put a button which will be displayed along with some data in the view file I specified in "itemView" field of the CListView widget, but instead of the styled button for every list item, I am just getting it or the first list item. My code in the _view file is:
<div id="listView">
<div class="thedata">
...some data
</div>
<div id="buttons">
<?php
$this->widget('zii.widgets.jui.CJuiButton', array(
'buttonType'=>'button',
'name'=>'btnJobs',
'caption'=>'Manage Jobs',
'options'=>array('icons'=>'js:{primary:"ui-icon-wrench"}'),
'onclick'=>'js:function(){alert("Manage Jobs clicked."); this.blur(); return false;}',
));
?>
</div>
</div>
and the code for CListView widget is just the bare minimum:
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_view'
));
any suggestions?
Try passing in a unique ID to the CJuiButton, like so:
<?php
$this->widget('zii.widgets.jui.CJuiButton', array(
'id'=>'button'.$data->id, // add a unique ID here (could use $index instead of $data->id)
'buttonType'=>'button',
'name'=>'btnJobs',
'caption'=>'Manage Jobs',
'options'=>array('icons'=>'js:{primary:"ui-icon-wrench"}'),
'onclick'=>'js:function(){alert("Manage Jobs clicked."); this.blur(); return false;}',
));
?>
The problem is that since all of your buttons have the same 'name' (and therefore 'id') jQuery is only binding to the first one. Making sure each button has a unique ID should fix this, so jQuery will bind correctly.

Magento Move attributes.phtml

i need to remove short description in the view.phtml and replace with attribute.phtml tab...how to do it? Thanks.
Edit your theme's template/catalog/product/view.phtml (not the base theme's, that can get overwritten) and replace this:
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<h2><?php echo $this->__('Quick Overview') ?></h2>
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>
with this:
<?php echo $this->getChildHtml('additional') ?>
And further down where you see the same line delete it. This avoids duplication.

Resources