everyeurocounts
Forum Replies Created
-
Forum: Plugins
In reply to: [WordPress REST API (Version 2)] catch all outputquick draft of the mu-plugin https://github.com/ambrosedheffernan/cache-wp-rest-api.git
Forum: Hacks
In reply to: After new post creation, divert back to posts listyes hook into ‘wp_insert_post’ and use wp_redirect() to the page you want, you will need to identify what post list you are referring too, if its just the standard posts, its https://www.url./wp-admin/edit.php.
If you are adding a lot of posts, you can create a function to add your content, terms, etc and do it in blocks (maybe 20 posts at a time) it would be much faster than using the wp create post process. But you need to be comfortable with php for either of the above or comfortable with html for the second option.
Forum: Hacks
In reply to: how can add jquery code in metabox?for the jquery code, you need to either replace “$” with “jQuery” or define $ as jQuery. WP uses non.conflict jQuery as default. If you are using chrome, right click and go to “inspect element” and click on console, you will see “$” is not defined. You can insert this into a metabox (is it the content metabox???) but you have to make sure jquery is loaded before the metabox is outputted into the page. i.e. if in the content metabox, recent themes load jquery in the footer so any jquery in the_content will not be defined, if that makes sense?
BTW the code you have there at the top of the page is a static page, the wp theme you are using will add the head and body tags in your header as caustastic has mentioned (right click and view source code), so you are duplicating these…look up wp page templates or rewrite rule to create a page for the code above rather than adding into a metabox (which is stored in the db).
Your php code is also not suitable for functions.php. You should not ideally run code here as it will run for every load, you should only define functions here and add_actions or filters to run the functions as needed. research these as well.
My advice to you would be to learn the load pattern of wp (https://theme.fm/2011/09/wordpress-internals-how-wordpress-boots-up-2315) then you easily understand where to add your code.
Forum: Hacks
In reply to: Admin submenus add taxonomy pagehi mate thanks for the reply but i’m not sure if im applying this right, you add ‘taxonomies’ => category or the taxonomy name ?
i did this but no result, the taxonomies dont appear in the menu selected. see below for code:
$args = array_merge( // Default array( 'label' => $plural, 'labels' => $labels, 'taxonomies' => array('category'), 'public' => true, 'exclude_from_search' => true, 'query_var' => true, 'show_ui' => true, 'supports' => array('title', 'editor'), 'show_in_menu' => 'marketdisplayoptions', 'show_in_nav_menus' => true, '_builtin' => false, ), // Given args $this->post_type_args ); // Register the post type register_post_type($this->post_type_name, $args);
Forum: Plugins
In reply to: [WP-PageNavi] Pagination page 2 for a certain number of posts breaksok i couldn’t get that solution working with a post variable so i did it through session + Ajax instead, seems to be working ok for the moment:
php:
add_action('wp_ajax_postperpage', 'postperpage'); add_action('wp_ajax_nopriv_postperpage', 'postperpage'); function postperpage() { if ( !wp_verify_nonce( $_POST['nonce'], "postperpage_nonce")) { exit("unverified request"); } if(!$_SESSION) { session_start(); } $postsperpage = sanitize_text_field($_POST['ppage']); $_SESSION['postperpage'] = $postsperpage; echo $postsperpage; exit(); } function my_custom_posts_per_page( $query ) { if(!$_SESSION) { session_start(); } if($_SESSION['postperpage']) { $perpage= $_SESSION['postperpage']; } else { $perpage=20; } $query->set( 'posts_per_page', $perpage); } add_filter('parse_query', 'my_custom_posts_per_page');
jquery
function sortPageSubmit(){ var postperpage = jQuery('#perpage').val(); console.log(postperpage); jQuery.ajax({ type: 'POST', url: "/wp-admin/admin-ajax.php", data: { action: 'postperpage', ppage: postperpage, nonce: "<?php echo $nonce ?>", }, success: function (output) { document.getElementById("sortbox").submit(); } }); }
sample html:
<select id="perpage" name="perpage" onchange="sortPageSubmit()"> <?php echo '<option value="'.$perpage.'" selected="selected">'.$perpage.'</option>'; foreach ($postsperpage as $option) { echo '<option value="'.$option.'">'.$option.'</option>'; }?> </select>
Forum: Hacks
In reply to: add page template by nameThanks a million for this, it never occurred to me to check the database for a solution! I got it working using a relative url + a function to check in the plugin if not found in the theme.
Forum: Hacks
In reply to: WordPress custom post_typei may be corrected on this but i think wp_insert_post only supports one post at a time. So to get what you want you would
$post_type=array('article'); if (!empty ($post_type) ) { $post_type[] = 'image'; } // etc $ids= array(); foreach ($arrays as $posttype) { $ids[] = wp_insert_post( array('post_type' => $posttype ) ); }
It must be noted that each of the posts above will be empty…there is no content but adjust the array as you need it: https://codex.www.ads-software.com/Function_Reference/wp_insert_post
Forum: Hacks
In reply to: Taxonomy and post typesWhat you can do is create a new post type for the company. so you can use the post editor to make the changes or a front end submit.
On your movie post type use the post meta (add_post_meta) function to save the post id of the production company when you are saving the post. (use meta box within the post and populate with a list of company e.g.
get_posts( array('post_type'=>'company') );
There are plenty of topics on each!
Forum: Hacks
In reply to: using Filters in functionsok thanks…you might shed some light on this…the apply_filter is located in a plugin and the function in the theme over-ride is responding to a $_post event on a “view” within a class in the plugin.
i.e. if the submit info is true, the function fires and within the function the filter is applied, i guess the apply_filters in the plugin is fired before the theme add_filter?
Forum: Hacks
In reply to: using Filters in functionsForum: Hacks
In reply to: Hook into add_term of custom taxonomyperfect, thank you ??
Forum: Hacks
In reply to: jQuery .post save to databasesmall type in the above….
should be
add_action('wp_ajax_tempsave', 'tempsave'); add_action('wp_ajax_nopriv_tempsave', 'tempsave');
Forum: Hacks
In reply to: jQuery .post save to databasethanks for this, it put me on the right track!
The 1st issue was the datepicker wasn’t triggering a change event. There is a function within datepicker for this (onSelect) but i couldn’t get it to work with any functions including a simple alert(). In the end i found a post suggesting that you use onSelect to trigger a change event….
Also i couldn’t get .post to work with the datepicker at all so i used .ajax.
Ill add in the nounce after. Thanks for your help, brilliant as usual!
page template:
jQuery(document).ready(function () { jQuery('#MyDate').datepicker({ minDate: '+2', maxDate: new Date(2014, 1, 28), dateFormat: 'yy-mm-dd', beforeShowDay: function (date) { var string = jQuery.datepicker.formatDate('dd/mm/yy', date); return [array.indexOf(string) == -1]; }, onSelect: function (dateText) {//trigger the change event when value "selected" jQuery(this).change(); } }).change(function () { var postid = '<?php echo esc_js($posted_id); ?>'; var pdate = jQuery(this).val(); //select updated value jQuery.ajax({ type: "POST", url: "/wp-admin/admin-ajax.php", data: { action: 'tempsave', postid: postid, postdate: pdate, status: 'waiting' }, success: function (data) {//handle return jQuery("#feedback").html(data); } }); }); });
and in theme functions
function tempsave(){ $postidcheck = strtotime($_POST['postdate']); global $wpdb; $postid = (int)$_POST['postid']; $post_date = date('Y-m-d H:i:s',$postidcheck); $status = $_POST['status']; $time = date('y-m-d H:i:s'); if($wpdb->update('wp_posts',array( 'post_date'=>$post_date, 'post_date_gmt'=>$post_date, 'post_modified'=>$time, 'post_status'=>$status ),array ('ID'=>$postid ))===FALSE){ echo "Error"; } else { echo "Pending payment the date you selected has been reserved for 10 minutes"; } die(); } add_action('wp_ajax_addCustomer', 'addCustomer'); add_action('wp_ajax_nopriv_addCustomer', 'addCustomer');
Forum: Hacks
In reply to: jQuery .post save to databaseOk 1st clumsy attempt ??
Two issues 1. The datepicker remains open after you select a date
2. Its not working — do you need a wpdb call rather than update_post?jquery
jQuery(document).ready(function() { jQuery('#MyDate').datepicker({ minDate: '+2', maxDate: new Date(2014, 1,28), dateFormat: 'yy-mm-dd', beforeShowDay: function(date){ var string = jQuery.datepicker.formatDate('dd/mm/yy', date); return [ array.indexOf(string) == -1 ]; } }).change(function($MyDate) { var wdate = $('#MyDate').val(); $.post( ajaxurl , { action: temp_save, post_id: <?php echo $posted_id ?>, post_date: wdate }); }); var bf = jQuery('#stotal').val(); var vf = parseInt(bf)*.21; jQuery('#vat').val(vf); vtf = (parseFloat(vf)+parseFloat(bf)).toFixed(2); jQuery('#Total').val(vtf); });
add_action( 'wp_ajax_temp_save', 'temp_save' ); function temp_save () { $temp_submitted_post_time = $_POST['wdate']; $posting = $_POST['post_id']; global $wpdb; $wpdb->query( " UPDATE $wpdb->posts SET post_date = $temp_submitted_post_time WHERE ID = $posting " ); }
Forum: Hacks
In reply to: Change php date array to javascript arraythanks mate for your answer ??
sorry information was kinda generic i guess….$fdates is a variable from a database query.
Hyphens or slashes work ok with beforeshow day (i ended up using implode to string and a php insert into the javascript to create the array with slashes) i’ve included the code below if it helps anyone, just i was wondering if the json_encode could be used effectively for date arrays…
$comma_seperated = implode('","', $fdates); <script type="text/javascript"> var array = ["<?php echo $comma_seperated; ?>"]; jQuery(document).ready(function() { jQuery('#MyDate').datepicker({ beforeShowDay: function(date){ var string = jQuery.datepicker.formatDate('yy/mm/dd', date); return [ array.indexOf(string) == -1 ] } }); }); </script>