openbayou
Forum Replies Created
-
Never mind.
Turned out I had a function that was duplicating rendering of blocks. Problem is solved.
Forum: Developing with WordPress
In reply to: Comparing values in pre_get_postsIs this better to understand?
if (isset( $query->$qvars['opby_alerts'] )) { $query->set('tax_query', array(array('taxonomy' => 'post_format','field' => 'slug','terms' => array( 'post-format-status' ),'operator'=> 'IN'), 'orderby' =>'meta_value','meta_key', 'breaking_news'), 'date_query', array( 'before' => date( 'U' , array(get_field('status_time_duration') + get_the_time('U')) ) ), $query->set('posts_per_page', -1)); }
Forum: Fixing WordPress
In reply to: Have a block appear automatically based on post format?Who keeps moving my post? It was under developing worpdress themes because I’m trying to make my existing themes work with Gutenberg. Then it gets moved to ‘Everything else WordPress’ now it’s under ‘Fixing WordPress’.
Stop moving this post!
Forum: Fixing WordPress
In reply to: JS code works on new post but doesn’t when updatingD’oh!
In order for the script to run, it has to load a js file. I had it to load only for new posts.
if ( $hook == 'post-new.php' && 'post' == get_post_type() ) { wp_enqueue_script( 'admin-check', get_template_directory_uri() . '/js/admin-js.js', array ( 'jquery' ), 1, true); wp_enqueue_script( 'moment-js', get_template_directory_uri() . '/js/moment.min.js', array ( 'jquery' ), 1, true); }
Got rid of
if ( $hook == 'post-new.php' && 'post' == get_post_type() ) {
- This reply was modified 6 years, 8 months ago by openbayou.
Forum: Fixing WordPress
In reply to: custom code in functions.php overrides data on all postsFound my problem, didn’t have
$post
(It does work but open for a code check and suggestions)// Start the metabox function metabox_mp3_analyze() { add_meta_box('mp3_start_box', 'Analyze MP3', 'mp3_start_box', 'post', 'normal', 'default'); }; add_action( 'add_meta_boxes', 'metabox_mp3_analyze' ); // jQuery code function mp3_start_box(){ ?> <style type="text/css"> audio {display: none} </style> <script type="text/javascript"> jQuery(function(){ var objectUrl; jQuery("#audio").on("canplaythrough", function(e){ var seconds = e.currentTarget.duration; var duration = moment.duration(seconds, "seconds"); var hours = duration.hours(); var mins = duration.minutes(); var secs = duration.seconds(); if (hours < 10) { time_hour = "0" + hours + ":" ; } else { time_hour = hours + ":" ; }; if (mins < 10) { time_mins = "0" + mins + ":" ; } else { time_mins = mins + ":" ; }; if (secs < 10) { time_secs = "0" + secs } else { time_secs = secs }; jQuery("#duration").text(time_hour+time_mins+time_secs); jQuery('#timelength').val(time_hour+time_mins+time_secs); URL.revokeObjectURL(objectUrl); }); jQuery("#file").change(function(e){ var file = e.currentTarget.files[0]; jQuery("#filesize").text(file.size); jQuery('#size').val(file.size); objectUrl = URL.createObjectURL(file); jQuery("#audio").prop("src", objectUrl); }); }); </script> // input mp3 file and output results <input type="file" id="file" /> <audio id="audio"></audio> <p> <label>File Size:</label> <span id="filesize"></span> <input type="hidden" id="size" name="size" value=""/> </p> <p> <label>Song Duration:</label> <span id="duration"></span> <input type="hidden" id="timelength" name="time" value=""/> </p> <?php }; // save data to custom fields add_action('wp_head','mp3_start_box'); function analyize_mp3_save_w_analy() { global $post; global $pagenow; if ($pagenow == 'post.php') { if ( isset( $_POST['size'] ) ) if (!empty(sanitize_text_field($_POST["size"]))) { update_post_meta($post->ID, "length", sanitize_text_field( $_POST['size'] )); }; if ( isset( $_POST['time'] ) ) if (!empty(sanitize_text_field($_POST["time"]))) { update_post_meta($post->ID, "time", sanitize_text_field( $_POST['time'] )); }; $url = str_replace(array('https://','https://'), 'dts.podtrac.com/redirect.mp3/', get_post_meta( get_the_ID(), 'podcast_url', true )); $podcast_check = get_post_meta( get_the_ID(), 'podcast_url', true ); if ($url && get_post_meta( $post_id, 'podcast_url', true ) !== $url) { update_post_meta( $post_id, 'podcast_url', $url ); } } } add_action( 'save_post', 'analyize_mp3_save_w_analy' );
- This reply was modified 6 years, 10 months ago by openbayou.
Forum: Fixing WordPress
In reply to: custom code in functions.php overrides data on all postsfrom my functions.php file in my theme
Fixed
var hours = duration.hours(); var mins = duration.minutes(); var secs = duration.seconds(); if (hours < 10) { time_hour = "0" + hours + ":" ; } else { time_hour = hours + ":" ;}; if (mins < 10) { time_mins = "0" + mins + ":" ; } else { time_mins = mins + ":" ;}; if (secs < 10) { time_secs = "0" + secs} else { time_secs = secs}; jQuery("#duration").text(time_hour+time_mins+time_secs);
The above didn’t work but I’ve made some progress. I’ve fixed the hours but I’m having problems with the minutes.
if (hours < 10) {time = "0" + hours + ":"} else {time = hours + ":"}
This is what I’ve done so far:
var hours = duration.hours(); var mins = duration.minutes(); if (hours < 10) {time = "0" + hours + ":"} else {time = hours + ":"} time = time + if (mins < 10) {"0" + mins + ":"} else {mins + ":"} + ":" + duration.seconds();
Thanks again for the help.
Forum: Developing with WordPress
In reply to: Meta box has javascript code that messes up text editorThat was simple!
I removed the
jquery.com
as the source and replaced$
withjQuery
and it works.function analyize_mp3_add_meta_box() { add_meta_box( 'analyize_mp3-analyize-mp3', __( 'Analyize MP3', 'analyize_mp3' ), 'analyize_mp3_html', 'post', 'normal', 'default' ); } add_action( 'add_meta_boxes', 'analyize_mp3_add_meta_box' ); function analyize_mp3_html( $post) { wp_nonce_field( '_analyize_mp3_nonce', 'analyize_mp3_nonce' ); ?> <style type="text/css"> audio {display: none;} </style> <script type='text/javascript'>//<![CDATA[ jQuery(function(){ var objectUrl; jQuery("#audio").on("canplaythrough", function(e){ var seconds = e.currentTarget.duration; var duration = moment.duration(seconds, "seconds"); var time = ""; var hours = duration.hours(); if (hours > 0) { time = hours + ":" ; } time = time + duration.minutes() + ":" + duration.seconds(); jQuery("#duration").text(time); jQuery('#timelength').val(time); URL.revokeObjectURL(objectUrl); }); jQuery("#file").change(function(e){ var file = e.currentTarget.files[0]; jQuery("#filesize").text(file.size); jQuery('#size').val(file.size); objectUrl = URL.createObjectURL(file); jQuery("#audio").prop("src", objectUrl); }); });//]]> </script> <input type="file" id="file" /> <audio id="audio"></audio> <p> <label>File Size:</label> <span id="filesize"></span> <input type="hidden" id="size" name="size" value=""/> </p> <p> <label>Song Duration:</label> <span id="duration"></span> <input type="hidden" id="timelength" name="time" value=""/> </p> <?php }
- This reply was modified 6 years, 11 months ago by openbayou.
Forum: Developing with WordPress
In reply to: Combine pre_get_posts into one queryNever mind.
Forum: Developing with WordPress
In reply to: Combine pre_get_posts into one queryIn other words, is there a way take this query:
add_action( 'pre_get_posts', 'exclude_category' ); function ctrl_daily_posts( $query ){ if( $query->get( 'ctrl_daily' ) == 'posts' ){ $query->set( 'tax_query', array(array('taxonomy' => 'category','field' => 'slug','terms' => array( 'podcast-control-daily' ),'operator'=> 'IN'))); $query->set( 'posts_per_page', 5 ); } } add_action( 'pre_get_posts', 'ctrl_daily_posts', 10 );
and add it to the main query on top of this being already set:
function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set('tax_query', array(array('taxonomy' => 'category','field' => 'slug','terms' => array( 'podcast-control-daily' ),'operator'=> 'NOT IN'),array('taxonomy' => 'post_format','field' => 'slug','terms' => array( 'post-format-status' ),'operator'=> 'NOT IN'))); $query->set( 'posts_per_page', 15 ); } return $query;} add_action( 'pre_get_posts', 'exclude_category' );
Forum: Developing with WordPress
In reply to: Combine pre_get_posts into one queryI don’t know at this point. I’ve been working on this for so much that I’m probably over-thinking my problem and I probably made it more complex that it’s suppose to be.
Basically, I’m trying to find a way to have one query then separate posts based on settings. For example, one query has 15 posts but stripped out posts from the category
podcast-control-daily
and then another query with posts that are in categorypodcast-control-daily
and put those back into the main_query. What happens is sometimes those posts with a categorypodcast-control-daily
get pushed to the bottom and are no longer shown on the front page.The code above does work, my only problem with it is that it does two queries and I would like it to be one.
Forum: Developing with WordPress
In reply to: Combine pre_get_posts into one querySo it’s easier to have two queries instead of trying to get two queries into the main query?
Forum: Developing with WordPress
In reply to: Remove attachments from post using preg_replace?Now it works.
Forum: Developing with WordPress
In reply to: Combine two preg_replace into oneThanks for the help.
$imgpatterns = array ('/<img[^>]+./','/(http|https):\/\/.*\/(.*)\.(jpg|gif|png)/'); preg_replace($imgpatterns, "", $post->post_content)));