Get the URL video from "post-format-video" - wordpress

I'm creating a dynamic section in my homepage with only posts format video. Now i need to get the URL from this videos...
I already got the Title, link and the date:
<div class="container">
<div class="row">
<div id="layer-videos-section">
<?php
$myposts = new WP_Query( array(
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => 'post-format-video'
)
)
) );
// Open the loop
if ( $myposts->have_posts() ) : while ( $myposts->have_posts() ) : $myposts->the_post();
$year = mysql2date('Y', $post->post_date);
$month = mysql2date('n', $post->post_date);
$day = mysql2date('j', $post->post_date);
?>
<p>
<span class="the_article">
<?php the_title(); ?>
</span>
<span class="the_day">
<?php the_time('j F Y'); ?>
</span>
</p>
<?php
// Close the loop
endwhile; endif;
// Reset $post data to default query
wp_reset_postdata();
?>
</div>
</div>

I got it!
I installed the plugin Featured Video Plus and got the vídeo url using a native function from this plugin:
get_the_post_video_url( $post_id )

Related

Wordpress, inserting URL in a shortcode

I'm trying to display/insert a url into the shortcode below:
<?php echo do_shortcode('[sc_embed_player fileurl="http://www.example.com/wp-content/uploads/my-music/mysong.mp3"]'); ?>
I'm using a ACF field called "add_audio" which is a mp3 URL.
I used the default get field ( <?php the_field('field_name'); ?> )
code to call the the url.
I made a variable too and called ($variable) too.
But nothing worked!!
Here's the error i get
"Prase error:syntax error, unexpected 'add_audio'(T_STRING),
expecting,''or')'in
/app/public/wp-content/oxygen/component-framework/components/layouts/code-block.php(33):eval()'d
code on line 43"
I used Oxygenbuilder plugin and ACF plugins.
<?php
/*
* Easy Query Shortcode
* [easy_query container="div" template="template_906184" posts_per_page="20" post_type="audio_files"]
*/
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => array('audio_files'),
'post_status' => 'publish',
'order' => 'DESC',
'orderby' => 'date',
'posts_per_page' => 20,
'paged' => $paged,
);
// WP_Query
$eq_query = new WP_Query( $args );
if ($eq_query->have_posts()) : // The Loop
$eq_count = 0;
?>
<div class="wp-easy-query paging-style-default grey">
<div class="wp-easy-query-posts">
<div>
<?php
while ($eq_query->have_posts()): $eq_query->the_post();
$eq_count++;
?>
<div id="div_block-17-25" class="ct-div-block audio-div">
<h1 id="headline-18-25" class="ct-headline">
<?php the_title(); ?></h1>
<div id="div_block-20-25" class="ct-div-block">
<?php echo do_shortcode('[sc_embed_player_template1 fileurl="<?php the_field('add_audio'); ?>"]'); ?>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
</div>
<?php include(EQ_PAGING); ?>
</div>
<?php endif; ?>
Simply Try Removing from your Code write it as follows:
<?php echo do_shortcode('[sc_embed_player_template1 fileurl="'.the_field('add_audio').'"]'); ?>

Multiple custom post query is not working

I am trying to display same custom post query multiple time in same page. The between the post is it will call different custom taxonomy based on one custom post type. When I am trying to call same custom post second time its not working. But showposts =2 is working but I need to display one post for a single post query. Here is the codes:
<div class="col-sm-6">
<?php
$querevent = new WP_Query( array(
'post_type' => 'tatstory', // name of post type.
'showposts' => 1,
) );
if ( $querevent->have_posts() ):
// Yep, we have posts, so let's loop through them.
while ( $querevent->have_posts() ) : $querevent->the_post(); ?>
<?php if ( has_term('event','eventname' ) && has_term('featured-in-story-page','fetstory' )) { ?>
<div class="listing_inner">
<div class="listing_img">
<?php the_post_thumbnail( 'shop-story', array( 'class' => 'img-fluid' ) ); ?>
</div>
<div class="listing_texts">
<p class="event yellow">Event</p>
<h2><?php the_title(); ?></h2>
</div>
</div>
<?php
} ?>
<?php endwhile;
else :
// No, we don't have any posts, so maybe we display a nice message
echo "<p class='no-posts'>" . __( "Sorry, there are no posts at this time." ) . "</p>";
endif;
?>
</div>
<div class="col-sm-6">
<?php
$quernews = new WP_Query( array(
'post_type' => 'tatstory', // name of post type.
'showposts' => 1,
) );
if ( $quernews->have_posts() ):
// Yep, we have posts, so let's loop through them.
while ( $quernews->have_posts() ) : $quernews->the_post(); ?>
<?php if ( has_term('news','eventname' ) && has_term('featured-in-story-page','fetstory' )) { ?>
<div class="listing_inner">
<div class="listing_img">
<?php the_post_thumbnail( 'shop-newscat', array( 'class' => 'img-fluid' ) ); ?>
</div>
<div class="listing_texts_right">
<p class="event blue">News</p>
<h2><?php the_title(); ?></h2>
</div>
</div>
<?php } ?>
<?php endwhile;
wp_reset_postdata();
else :
// No, we don't have any posts, so maybe we display a nice message
echo "<p class='no-posts'>" . __( "Sorry, there are no posts at this time." ) . "</p>";
endif;
?>
First i would change your WP_Query, example:
$query = new WP_Query( array(
'post_type' => 'tatstory',
'posts_per_page' => '1',
'tax_query' => array(
array (
'taxonomy' => 'eventname',
'field' => 'slug',
'terms' => 'news',
),
array (
'taxonomy' => 'fetstory',
'field' => 'slug',
'terms' => 'featured-in-story-page',
)
),
) );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// display content
}
} else {
// display when no posts found
}
wp_reset_postdata(); // Restore original Post Data
The query will only collect posts that have the correct terms set.
Restoring original Post Data on the end (wp_reset_postdata()) may help you with calling a new WP_Query again. But I don't know of any reason why you cannot call it twice in a single page template.

WP_Query taxonomy terms add one more post

I'm working with taxonomy page order by terms whit different WP_Query. AT the last of every loop something add a "post" that have page title and info from the before post. Very strange thing.
I don't find nothing about this (neither I know how to search this). Thanks por your time. My doce is this:
<?php
$the_query = new WP_Query( array(
'post_type' => 'intervencion',
'tax_query' => array(
array (
'taxonomy' => 'especialidad',
'field' => 'slug',
'terms' => 'bariatrica_ok',
)
),
) );
while ( $the_query->have_posts() ) : $the_query->the_post();?>
<?php $meta = get_post_meta(get_the_ID()); ?>
<div class="col-lg-3 col-md-4 col-sm-6">
<div class="ficha">
<?php if ( has_post_thumbnail() ) { ?>
<?php the_post_thumbnail('thumb_intervenciones', array('class' => 'img-responsive')); ?>
<?php } ?>
<h2><?php echo get_the_title(); ?></h2>
<p class="condiciones">Todo</br>incluido por:</p>
<p class="precio"><?php echo $meta['intervenciones_precio_intervencion'][0]; ?> €</p>
<a class="ficha-btn" href="<?php the_permalink()?>">Solicitar cita</a>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
The result at the bottom of the list is:
enter image description here

Wordpress order custom post type

I'm hoping someone can help me with this. I'm new to php so it is very much learning on the job.
I am customising an existing Wordpress theme but I am facing a problem with the themes advanced search/results.
The theme has no way to order search results and I know that the default order for Wordpress is by date. Currently if I perform a search, the results are displayed in date order but I need the results to be price high to low.
The current code is as follows
<?php /* If there are no posts to display, such as an empty archive page */ ?>
<?php if ( ! have_posts() ) : ?>
<article id="post-0" class="post error404 not-found">
<h1 class="posttitle"><?php _e( 'Not Found', THE_LANG ); ?></h1>
<div class="entry">
<p><?php _e( 'Apologies, but no results were found for the requested property archive. Perhaps searching will help find a related post.', THE_LANG ); ?></p>
</div>
</article>
<?php endif; ?>
<div class="nvr-prop-container row">
<?php if( have_posts() ){ ?>
<div class="search-title twelve columns">
<h4><?php _e('Search Result', THE_LANG); ?> (<?php echo $wp_query->post_count; ?>)</h4>
</div>
<?php
$nvr_idnum = 0;
$nvr_typecol = "nvr-prop-col";
$nvr_imgsize = "property-image";
?>
<ul id="nvr-prop-search" class="<?php echo esc_attr( $nvr_typecol ); ?>">
<?php
while ( have_posts() ) : the_post();
$nvr_idnum++;
echo nvr_prop_get_box( $nvr_imgsize, get_the_ID(), 'element columns', $nvr_unit, $nvr_cursymbol, $nvr_curplace );
$nvr_classpf="";
endwhile; // End the loop. Whew.
?>
I then decided to try and sort the results so I created
$sort_properties = new WP_Query(array(
'post_type' => 'properties',
'meta_key' => $nvr_initial.'_price',
'meta_value' => $nvr_price,
'orderby' => 'meta_value_num date',
'order' => 'DESC',
));
<?php /* If there are no posts to display, such as an empty archive page */ ?>
<?php if ( ! have_posts() ) : ?>
<article id="post-0" class="post error404 not-found">
<h1 class="posttitle"><?php _e( 'Not Found', THE_LANG ); ?></h1>
<div class="entry">
<p><?php _e( 'Apologies, but no results were found for the requested property archive. Perhaps searching will help find a related post.', THE_LANG ); ?></p>
</div>
</article>
<?php endif; ?>
<div class="nvr-prop-container row">
<?php if( $sort_properties->have_posts() ){ ?>
<div class="search-title twelve columns">
<h4><?php _e('Search Result', THE_LANG); ?> (<?php echo $wp_query->post_count; ?>)</h4>
</div>
<?php
$nvr_idnum = 0;
$nvr_typecol = "nvr-prop-col";
$nvr_imgsize = "property-image";
?>
<ul id="nvr-prop-search" class="<?php echo esc_attr( $nvr_typecol ); ?>">
<?php
while ( $sort_properties->have_posts() ) : $sort_properties->the_post();
$nvr_idnum++;
echo nvr_prop_get_box( $nvr_imgsize, get_the_ID(), 'element columns', $nvr_unit, $nvr_cursymbol, $nvr_curplace );
$nvr_classpf="";
endwhile; // End the loop. Whew.
?>
Now when I perform a search, the posts are sorted based on price which is fantastic but... now regardless of how I search all of the site posts are now being displayed.
I felt I was so close to finding a solution but I would very much grateful if someone cold advise me with this.
Kind regards
S
Have you tried to order only by the 'meta_val_num' without the 'date' like:
$args = array(
'post_type' => 'product',
'orderby' => 'meta_value_num',
'meta_key' => 'price',
);
$query = new WP_Query( $args );
Code from: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
I think you have to add the Search Parameter and probably use the new meta_query structure:
$search_query = get_search_query();
$sort_properties = new WP_Query(array(
'post_type' => 'properties',
's' => $search_query,
'orderby' => 'meta_value_num',
'meta_query' => array(
'key' => $nvr_initial.'_price',
'value' => $nvr_price,
)
));
I remember having some trouble, not using "meta_query" => array() for multiple conditions.

Event Organiser date in loop

I am using WordPress in combination with WP Events Organiser. On my index.php, I want to display events and posts in the same loop, but only categories of "startseite" should be displayed either for the events as well as for the posts. At the moment it is working like this:
<?php global $wp_query;
$args = array(
'post_type' => array('post','event'),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'category',
'terms' => 'startseite',
'field' => 'slug'
),
array(
'taxonomy' => 'event-category',
'terms' => 'startseite',
'field' => 'slug'),
));
query_posts( $args ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
... further on the loop:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="d-1of3" id="post-<?php the_ID(); ?>" <?php post_class( 'cf' ); ?> role="article">
<div class="entry-content">
<h2 class="h2 entry-title"><?php the_title(); ?></h2>
<p class="byline entry-meta vcard">
<?php printf( __( '', 'bonestheme' ).' %1$s',
'<time class="updated entry-time" datetime="' . get_the_time('Y-m-d') . '" itemprop="datePublished">' . get_the_time(get_option('date_format')) . '</time>'
); ?>
</p>
<section class="cf">
<?php the_content(); ?>
<?php echo eo_get_the_start('jS M YY'); ?>
</section>
</div>
<?php the_post_thumbnail( 'large' ); ?>
</article>
<?php endwhile; endif; ?>
Now I would like to display the date of the Event. I have found the following link with an example: http://codex.wp-event-organiser.com/function-eo_get_events.html
But I can't figure out how to change my code just to display the date. AND also it would be great to order the events by the date. Thanks for your help!!
just check the documentation in here.
Basically you add this:
echo eo_get_the_start('jS M YY');
Where you need to show the date.

Resources