jQuery Ajax returning 404 Error, but correct Response

When you include wp-blog-header.php, you end up bootstrapping the whole WordPress setup routine. The function wp() is called, which calls $wp->main(), which in turn calls various setup functions. One of these is $wp->query_posts(), which calls $wp_the_query->query(), which in turn calls WP_Query‘s parse_query() function. I suspect that the 404 indication is generated in there (your AJAX … Read more

How do I debug a WordPress plugin?

There’s this excellent Q&A at WordPress Stack Exchange, lots of knowledgeable folks explaining their debugging techniques: How do you debug plugins? In the Javascript arena you basically need <script>console.log(‘the value is’ + variable);</script>. And use Google Chrome inspector and/or Firebug. In PHP, it depends on where things are happening or where you want the output. … Read more

How to load all server side data on initial vue.js / vue-router load?

My approach is to delay construction of the store and main Vue until my AJAX call has returned. store.js import Vue from ‘vue’; import Vuex from ‘vuex’; import actions from ‘./actions’; import getters from ‘./getters’; import mutations from ‘./mutations’; Vue.use(Vuex); function builder(data) { return new Vuex.Store({ state: { exams: data, }, actions, getters, mutations, }); … Read more

WordPress path url in js script file

According to the WordPress documentation, you should use wp_localize_script() in your functions.php file. This will create a Javascript Object in the header, which will be available to your scripts at runtime. See Codex Example: <?php wp_localize_script(‘mylib’, ‘WPURLS’, array( ‘siteurl’ => get_option(‘siteurl’) )); ?> To access this variable within in Javascript, you would simply do: <script … Read more

Getting Error: Object doesn’t support property or method ‘assign’

As others have mentioned, the Object.assign() method is not supported in IE, but there is a polyfill available, just include it “before” your plugin declaration: if (typeof Object.assign != ‘function’) { Object.assign = function(target) { ‘use strict’; if (target == null) { throw new TypeError(‘Cannot convert undefined or null to object’); } target = Object(target); … Read more

Multiple excerpt lengths in wordpress

How about… function excerpt($limit) { $excerpt = explode(‘ ‘, get_the_excerpt(), $limit); if (count($excerpt) >= $limit) { array_pop($excerpt); $excerpt = implode(” “, $excerpt) . ‘…’; } else { $excerpt = implode(” “, $excerpt); } $excerpt = preg_replace(‘`\[[^\]]*\]`’, ”, $excerpt); return $excerpt; } function content($limit) { $content = explode(‘ ‘, get_the_content(), $limit); if (count($content) >= $limit) { … Read more

WordPress REST API (wp-api) 404 Error: Cannot access the WordPress REST API

UPDATED NEW WAY I also faced similar problem in a local project. I used index.php after my project url and it worked. http://localhost/myproject/index.php/wp-json/wp/v2/posts If it displays a 404 error then update permalinks first (see “Paged Navigation Doesn’t Work” section If it works, maybe you need to enable mod_rewrite, on ubuntu: a2enmod rewrite sudo service apache2 … Read more

Display custom order meta data value in email notifications WooCommerce

You have some minor mistakes, via the if condition “$email->id == …” you can target the mails How to target other WooCommerce order emails ‘customer_completed_order’ ‘customer_processing_order’ ‘customer_on_hold_order’ ‘customer_refunded_order’ ‘customer_reset_password’ ‘customer_invoice’ ‘customer_new_account’ ‘customer_note’ ‘cancelled_order’ ‘failed_order’ ‘new_order’ function woocommerce_email_order_invoice_number( $order, $sent_to_admin, $plain_text, $email ) { // For ‘new order’ if ( $email->id == ‘new_order’ ) { // … Read more