Thumbnail Grid shows up in reverse order - javascript

I have a wordpress site that uses a thumbnail grid (9 posts, 3 posts wide, responsive ) the featured image on each post creates the grid.
My code that controls the grid is
<?php
/**
* controls main grid images
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class('col-md-4 col-sm-4 pbox '); ?>>
<div class = "box-ovrly">
<h2 class="box-title"><?php the_title(); ?></h2>
<div class="box-meta"><?php the_category(', '); ?></div>
</div>
<?php
$thumb = get_post_thumbnail_id();
$img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)
$image = aq_resize( $img_url, 750, 560, true ); //resize & crop the image
?>
<?php if($image) : ?>
<img class="img-responsive" src="<?php echo $image ?>"/>
<?php endif; ?>
</article><!-- #post-## -->
It creates a grid but it shows up in the reverse order (9 to 1, instead of 1 to 9) This wouldn't be a huge deal but I have 'next' and 'previous' buttons which don't co-ordinate to the post.
Ex. on my first post the 'previous' button shows up cause it thinks its on the 9th post, etc.
the back/next menu is created with the following
function web2feel_content_nav( $nav_id ) {
global $wp_query, $post;
// Don't print empty markup on single pages if there's nowhere to navigate.
if ( is_single() ) {
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous )
return;
}
// Don't print empty markup in archives if there's only one page.
if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
return;
$nav_class = ( is_single() ) ? 'post-navigation' : 'paging-navigation';
?>
<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?> row">
<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'web2feel' ); ?></h1>
<?php if ( is_single() ) : // navigation links for single posts ?>
<?php previous_post_link( '<div class="nav-previous col-xs-6">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'web2feel' ) . '</span> %title' ); ?>
<?php next_post_link( '<div class="nav-next col-xs-6">%link</div>', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'web2feel' ) . '</span>' ); ?>
<?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
<?php if ( get_next_posts_link() ) : ?>
<div class="nav-previous col-md-6"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'web2feel' ) ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next col-md-6"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'web2feel' ) ); ?></div>
<?php endif; ?>
<?php endif; ?>
</nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
<?php
}

Related

I want to show product categories and not product directly on Dokan store page

I am using Dokan for a Multipurpose store. I have already set up 2 vendors with their individual products. When I click on each vendor, I want to see the categories of products and not the products directly. I need guidance on how to go about it.
Here is the link to the website: https://entertainers.vipclubguest.com/
Thank you.
SO, after contacting the plugin owner, he could not help as the edit I need is out of their support scope. However, he gave me a pointer of where to look and below is the code that is in the file:
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$store_user = dokan()->vendor->get( get_query_var( 'author' ) );
$store_info = $store_user->get_shop_info();
$map_location = $store_user->get_location();
$layout = get_theme_mod( 'store_layout', 'left' );
get_header( 'shop' );
if ( function_exists( 'yoast_breadcrumb' ) ) {
yoast_breadcrumb( '<p id="breadcrumbs">', '</p>' );
}
?>
<?php do_action( 'woocommerce_before_main_content' ); ?>
<div class="dokan-store-wrap layout-<?php echo esc_attr( $layout ); ?>">
<?php if ( 'left' === $layout ) { ?>
<?php dokan_get_template_part( 'store', 'sidebar', array( 'store_user' => $store_user, 'store_info' => $store_info, 'map_location' => $map_location ) ); ?>
<?php } ?>
<div id="dokan-primary" class="dokan-single-store">
<div id="dokan-content" class="store-page-wrap woocommerce" role="main">
<?php dokan_get_template_part( 'store-header' ); ?>
<?php do_action( 'dokan_store_profile_frame_after', $store_user->data, $store_info ); ?>
<?php if ( have_posts() ) { ?>
<div class="seller-items">
<?php woocommerce_product_loop_start(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
</div>
<?php dokan_content_nav( 'nav-below' ); ?>
<?php } else { ?>
<p class="dokan-info"><?php esc_html_e( 'No products were found of this vendor!', 'dokan-lite' ); ?></p>
<?php } ?>
</div>
</div><!-- .dokan-single-store -->
<?php if ( 'right' === $layout ) { ?>
<?php dokan_get_template_part( 'store', 'sidebar', array( 'store_user' => $store_user, 'store_info' => $store_info, 'map_location' => $map_location ) ); ?>
<?php } ?>
</div><!-- .dokan-store-wrap -->
<?php do_action( 'woocommerce_after_main_content' ); ?>
<?php get_footer( 'shop' ); ?>

Wordpress: Removing shortcodes from search results page

Been researching on this issue. Found lots of advice but none that seem to work or that applies to my site. In the search results page, my website displays shortcodes from plugins as code. I'd like to hide this code from being displayed.
This is the code from my search.php page
<?php
/**
* Search results page
*
* #package shaka-pt
*/
get_header();
$shaka_sidebar = get_field( 'sidebar', (int) get_option( 'page_for_posts' ) );
if ( ! $shaka_sidebar ) {
$shaka_sidebar = 'left';
}
get_template_part( 'template-parts/page-header' );
?>
<div id="primary" class="content-area container">
<div class="row">
<main id="main" class="site-main masonry col-xs-12<?php echo 'left' === $shaka_sidebar ? ' col-lg-9 col-lg-push-3' : ''; ?><?php echo 'right' === $shaka_sidebar ? ' col-lg-9' : ''; ?>" role="main">
<?php if ( have_posts() ) : ?>
<div class="grid js-pt-masonry row">
<div class="grid-sizer col-xs-12 col-sm-6 col-lg-4"></div>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content', 'search' ); ?>
<?php endwhile; ?>
</div>
<?php
the_posts_pagination( array(
'prev_text' => '<i class="fa fa-long-arrow-left"></i>',
'next_text' => '<i class="fa fa-long-arrow-right"></i>',
) );
?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php endif; ?>
</main>
<?php get_template_part( 'template-parts/sidebar', 'blog' ); ?>
</div>
</div>
<?php get_footer(); ?>
Here is the code from the template-parts/content-search.php
<?php
/**
* The template part for displaying results in search pages.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* #package shaka-pt
*/
$blog_columns = get_theme_mod( 'blog_columns', 6 );
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( array( 'grid-item', 'col-xs-12', 'col-sm-6', esc_attr( sprintf( 'col-lg-%s', $blog_columns ) ) ) ); ?>>
<!-- Featured Image -->
<?php if ( has_post_thumbnail() ) : ?>
<header class="hentry__header">
<a class="hentry__featured-image" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'post-thumbnail', array( 'class' => 'img-fluid' ) ); ?>
</a>
</header><!-- .hentry__header -->
<?php endif; ?>
<!-- Content Box -->
<div class="hentry__content entry-content">
<!-- Date -->
<time class="hentry__date" datetime="<?php the_time( 'c' ); ?>"><?php echo get_the_date(); ?></time>
<!-- Author -->
<span class="hentry__author"><i class="fa fa-user"></i> <?php echo esc_html__( 'By' , 'shaka-pt' ) . ' ' . get_the_author(); ?></span>
<!-- Content -->
<?php the_title( sprintf( '<h2 class="hentry__title">', esc_url( get_permalink() ) ), '</h2>' ); ?>
<p>
<?php echo wp_kses_post( get_the_excerpt() ); ?>
</p>
<p>
<?php printf( esc_html__( 'Read more %s', 'shaka-pt' ), the_title( '<span class="screen-reader-text">', '</span>', false ) ); ?>
</p>
<?php if ( has_category() || comments_open( get_the_ID() ) ) : ?>
<div class="hentry__meta meta">
<!-- Categories -->
<?php if ( has_category() ) : ?>
<span class="meta__item meta__item--categories"><?php the_category( ' ' ); ?></span>
<?php endif; ?>
<!-- Comments -->
<?php if ( comments_open( get_the_ID() ) ) : // Only show comments count if the comments are open. ?>
<span class="meta__item meta__item--comments"><?php ShakaHelpers::pretty_comments_number(); ?></span>
<?php endif; ?>
</div><!-- .hentry__meta -->
<?php endif; ?>
</div><!-- .hentry__content -->
</article><!-- #post-## -->
Once I had the same problem, it inserted shortcodes that I doesn't even used on my site, it was a "feature" of the theme... If I switched off the not used plugins, it looked like exactly this on the search result page. Don't know why exaclty on that page...:) My problem has been solved by editing and deleting this shortcodes from a search_result.php in my child theme.
I am guessing those shortcodes come from the posts that appear in the search results, assuming the red text is the excerpt.
You can strip these shortcodes before passing it
using strip_shortcodes()
Using your code from template-parts/content.php inside your content if else statement you make a call to the_content(), which returns your full content including shortcodes. You could try using the following code:
strip_shortcodes(
the_content( sprintf(
esc_html__( 'Read more %s', 'shaka-pt' ),
the_title( '<span class="screen-reader-text">"', '"
</span>', false )
) );
);
This should be your new content for template-parts/content.php
<?php
/**
* Template part for displaying posts.
*
* #package shaka-pt
*/
$blog_columns = get_theme_mod( 'blog_columns', 6 );
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( array( 'grid-item', 'col-xs-12', 'col-sm-6', esc_attr( sprintf( 'col-lg-%s', $blog_columns ) ) ) ); ?>>
<!-- Featured Image -->
<?php if ( has_post_thumbnail() ) : ?>
<header class="hentry__header">
<a class="hentry__featured-image" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'post-thumbnail', array( 'class' => 'img-fluid' ) ); ?>
</a>
</header><!-- .hentry__header -->
<?php endif; ?>
<!-- Content Box -->
<div class="hentry__content entry-content">
<!-- Date -->
<time class="hentry__date" datetime="<?php the_time( 'c' ); ?>"><?php echo get_the_date(); ?></time>
<!-- Author -->
<span class="hentry__author"><i class="fa fa-user"></i> <?php echo esc_html__( 'By' , 'shaka-pt' ) . ' ' . get_the_author(); ?></span>
<!-- Content -->
<?php the_title( sprintf( '<h2 class="hentry__title">', esc_url( get_permalink() ) ), '</h2>' ); ?>
<?php
$shaka_is_excerpt = ( 1 === (int) get_option( 'rss_use_excerpt', 0 ) );
if ( $shaka_is_excerpt ) : ?>
<p>
<?php echo strip_shortcodes(wp_kses_post( get_the_excerpt())); ?>
</p>
<p>
<?php printf( esc_html__( 'Read more %s', 'shaka-pt' ), the_title( '<span class="screen-reader-text">', '</span>', false ) ); ?>
</p>
<?php else :
/* translators: %s: Name of current post */
strip_shortcodes(
the_content( sprintf(
esc_html__( 'Read more %s', 'shaka-pt' ),
the_title( '<span class="screen-reader-text">"', '"
</span>', false )
) );
);
endif;
?>
<div class="hentry__meta meta">
<!-- Categories -->
<?php if ( has_category() ) : ?>
<span class="meta__item meta__item--categories"><?php the_category( ' ' ); ?></span>
<?php endif; ?>
<!-- Comments -->
<?php if ( comments_open( get_the_ID() ) ) : // Only show comments count if the comments are open. ?>
<span class="meta__item meta__item--comments"><?php ShakaHelpers::pretty_comments_number(); ?></span>
<?php endif; ?>
</div><!-- .hentry__meta -->
</div><!-- .hentry__content -->
</article><!-- .hentry -->
Try this : add this in your theme's functions.php, additionally you would wrap the strip_shortcodes in if statement so that it runs only when you need
// remove shortcode from excerpt
function remove_shortcode_from_excerpt($content) {
$content = strip_shortcodes( $content );
return $content;
}
add_filter('the_excerpt', 'remove_shortcode_from_excerpt');

if your press load more button it scrolls back to top of page

I added a load more button onto one of my category pages. I have three posts in a row and after two columns (6 posts) I have a load more button. The problem is when you press the load more button it scrolls back to the top. I'm assuming because the load more code is in the wrong spot, however I can't find the error. (you have to wrap content in div id=ajax) Does anyone have a solution? Thanks in advance.
by the way I am using this plugin
<?php
get_header();
get_template_part ('inc/carousel-food');
get_template_part ('inc/food-double-posts');
$the_query = new WP_Query( [
'posts_per_page' => 6,
'paged' => get_query_var('paged', 1),
'cat'=> 10
] );
if ( $the_query->have_posts() ) { ?>
<div id="ajax">
<?php
$i = 0;
while ( $the_query->have_posts() ) { $the_query->the_post();
if($i % 3 == 0) {
echo '</div><div class="row">';
}
?>
<article <?php post_class('col-md-4'); ?> >
<?php the_post_thumbnail('medium-thumbnail'); ?>
<h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="post-excerpt"><?php echo get_the_excerpt(); ?></p>
<?php get_template_part( 'share-buttons' ); ?>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'comment-count', 'none'); ?>
</article>
<?php
$i++;
}?>
</div>
<?php if(get_query_var('paged') < $the_query->max_num_pages) {
load_more_button();
}
}
elseif (!get_query_var('paged') || get_query_var('paged') == '1') {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
wp_reset_postdata();
get_footer();

How to redirect wpmu Directory "edit listing" button?

I am using a WordPress plugin that provides a front end editor to create a custom post type (directory). When I create a new directory listing the page redirects back to the /listings/my-listings/, however when I edit an existing listing and click the save button it dose not redirect. The page page instead refreshes and adds a # to the end of the URL (/listings/edit-listing/#). Could anyone look at this and help me to tweak the php or provide a javascript/jquery to redirect me back to the /listings/my-listings/?
I believe it has something to do with the .submit class at the bottom of the code...
Code:
<?php
get_header();
/**
* The template for displaying the Add/edit listing page.
* You can override this file in your active theme.
*
* #license GNU General Public License (Version 2 - GPLv2) {#link
http://www.gnu.org/licenses/gpl-2.0.html}
*/
global $wp_query, $wp_taxonomies, $post, $post_ID, $CustomPress_Core,
$Directory_Core;
$listing_data = '';
$selected_cats = '';
$error = get_query_var('dr_error');
$post_statuses = get_post_statuses(); // get the wp post status list
$options = $Directory_Core->get_options('general');
$allowed_statuses = $Directory_Core->get_options('general'); // Get the ones we allow
$allowed_statuses['moderation'] = (empty($allowed_statuses['moderation']) ) ? array('publish' => 1, 'draft'=> 1 ) : $allowed_statuses['moderation']; // Get the ones we allow
$allowed_statuses = array_reverse(array_intersect_key($post_statuses, $allowed_statuses['moderation']) ); //return the reduced list
//Are we adding a Listing?
if (is_page($Directory_Core->add_listing_page_id)) {
//Make an auto-draft so we have a post id to connect attachemnts to. Set global $post_ID so media editor can hook up. Watch the case
$post_ID = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $Directory_Core->post_type, 'post_status' => 'auto-draft' ) );
$listing_data = get_post($post_ID, ARRAY_A );
$listing_data['post_title'] = ''; //Have to have a title to insert the auto-save but we don't want it as final.
$editing = false;
}
//Or are we editing a listing?
if(is_page($Directory_Core->edit_listing_page_id)){
$listing_data = get_post( $_REQUEST['post_id'], ARRAY_A );
$post_ID = $listing_data['ID'];
$editing = true;
}
$post = get_post($post_ID);
if ( isset( $_POST['listing_data'] ) ) $listing_data = $_POST['listing_data'];
require_once(ABSPATH . 'wp-admin/includes/template.php');
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/post.php');
$editor_settings = array(
'wpautop' => true, // use wpautop?
'media_buttons' => true, // show insert/upload button(s)
'textarea_name' => 'listing_data[post_content]', // set the textarea name to something different, square brackets [] can be used here
'textarea_rows' => 10, //get_option('default_post_edit_rows', 10), // rows="..."
'tabindex' => '',
'editor_css' => '', // intended for extra styles for both visual and HTML editors buttons, needs to include the <style> tags, can use "scoped".
'editor_class' => 'required', // add extra class(es) to the editor textarea
'teeny' => false, // output the minimal editor config used in Press This
'dfw' => false, // replace the default fullscreen with DFW (needs specific css)
'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
);
$listing_content = (empty( $listing_data['post_content'] ) ) ? '' : $listing_data['post_content'];
wp_enqueue_script('set-post-thumbnail');
?>
<script type="text/javascript" src="<?php echo $Directory_Core->plugin_url . 'ui-front/js/jquery.tagsinput.min.js'; ?>" ></script>
<script type="text/javascript" src="<?php echo $Directory_Core->plugin_url . 'ui-front/js/media-post.js'; ?>" ></script>
<script type="text/javascript" src="<?php echo $Directory_Core->plugin_url . 'ui-front/js/ui-front.js'; ?>" >
</script>
<?php if ( !empty( $error ) ): ?>
<br /><div class="error"><?php echo $error . '<br />'; ?></div>
<?php endif; ?>
<div class="dr_update_form">
<form class="standard-form base" method="post" action="#" enctype="multipart/form-data" id="dr_update_form" >
<input type="hidden" id="post_ID" name="listing_data[ID]" value="<?php echo ( isset( $listing_data['ID'] ) ) ? $listing_data['ID'] : ''; ?>" />
<input type="hidden" name="post_id" value="<?php echo ( isset( $listing_data['ID'] ) ) ? $listing_data['ID'] : ''; ?>" />
<?php if(post_type_supports('directory_listing','title') ): ?>
<div class="editfield">
<label for="title"><?php _e( '<strong>Agent Name:</strong>', $Directory_Core->text_domain ); ?></label>
<input class="required" type="text" id="title" name="listing_data[post_title]" value="<?php echo ( isset( $listing_data['post_title'] ) ) ? esc_attr($listing_data['post_title']) : ''; ?>" />
<p class="description"><?php _e( 'Enter agents name here.', $Directory_Core->text_domain ); ?></p>
</div>
<?php endif; ?>
<!-- Start Add Featured Image / Agent Headshot-->
<?php if(post_type_supports('directory_listing','thumbnail') && current_theme_supports('post-thumbnails') ): ?>
<div class="editfield">
<div><strong>Agent Headshot:</strong></div>
<?php if(empty($options['media_manager']) ): ?>
<?php if(has_post_thumbnail()) the_post_thumbnail('thumbnail'); ?><br />
<script type="text/javascript">js_translate.image_chosen = '<?php _e("Feature Image Chosen", $Directory_Core->text_domain); ?>';</script>
<span class="upload-button">
<?php $class = ( empty($options['field_image_req']) && !has_post_thumbnail() ) ? 'required' : ''; ?>
<input type="file" name="feature_image" size="1" id="image" class="<?php echo $class; ?>" />
<button type="button" class="button"><?php _e('Add Agent Headshot', $Directory_Core->text_domain); ?></button>
</span>
<br />
<?php else: ?>
<div id="postimagediv">
<div class="inside">
<?php
$thumbnail_id = get_post_meta( $post_ID, '_thumbnail_id', true );
echo _wp_post_thumbnail_html($thumbnail_id, $post_ID);
?>
</div>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<!-- End Add Featured Image / Agent Headshot-->
<!-- Start Taxonimy, Category and custom All Services-->
<?php
//get related hierarchical taxonomies
$taxonomies = get_object_taxonomies('directory_listing', 'objects');
$taxonomies = empty($taxonomies) ? array() : $taxonomies;
//Loop through the taxonomies that apply
foreach($taxonomies as $taxonomy):
if( ! $taxonomy->hierarchical) continue;
$tax_name = $taxonomy->name;
$labels = $taxonomy->labels;
//Get this Taxonomies terms
$selected_cats = array_values( wp_get_post_terms($listing_data['ID'], $tax_name, array('fields' => 'ids') ) );
?>
<div id="taxonomy-<?php echo $tax_name; ?>" class="dr_taxonomydiv">
<label><?php echo $labels->all_items; ?></label>
<div id="<?php echo $tax_name; ?>_all" class="dr_tax_panel">
<?php
$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
?>
<ul id="<?php echo $tax_name; ?>_checklist" class="list:<?php echo $labels->name; ?> categorychecklist form-no-clear">
<?php wp_terms_checklist( 0, array( 'taxonomy' => $tax_name, 'selected_cats' => $selected_cats, 'checked_ontop' => false ) ) ?>
</ul>
</div>
</div>
<?php endforeach; ?>
<!-- End Taxonimy, Category and custom All Services-->
<div class="clear"><br /></div>
<!-- Start Custom Press / Custom Fields-->
<?php if ( isset( $CustomPress_Core ) ) : ?>
<?php echo do_shortcode('[custom_fields_input style="editfield"]'); ?>
<?php endif; ?>
<?php if ( !empty( $error ) ): ?>
<br /><div class="error"><?php echo $error . '<br />'; ?></div>
<?php endif; ?>
<!-- End Custom Press / Custom Fields-->
<!-- Start Select as Draft/Pyblic-->
<div class="editfield" >
<label for="title"><?php _e( 'Status', $Directory_Core->text_domain ); ?></label>
<div id="status-box">
<select name="listing_data[post_status]" id="listing_data[post_status]">
<?php
foreach($allowed_statuses as $key => $value): ?>
<option value="<?php echo $key; ?>" <?php selected( ! empty($listing_data['post_status'] ) && $key == $listing_data['post_status'] ); ?> ><?php echo $value; ?></option>
<?php endforeach; ?>
</select>
</div>
<p class="description"><?php _e( 'Please select a status for your listing. If you select your listing status as “Published” your listing will be made live and available for the public to view. If you select your listing status as “Draft” your listing will not be visible to the public and you can come back later to finish/publish.', $Directory_Core->text_domain ); ?></p>
</div>
<!-- End Select as Draft/Pyblic-->
<div class="submit">
<?php wp_nonce_field( 'verify' ); ?>
<input type="submit" value="<?php _e( 'Save Changes', $Directory_Core->text_domain ); ?>" name="update_listing">
<input type="button" value="<?php _e( 'Cancel', $Directory_Core->text_domain ); ?>" onclick="location.href='<?php echo get_permalink($Directory_Core->my_listings_page_id); ?>'">
</div>
<?php //echo do_shortcode('[ct_validate]') ; ?>
</form>
</div>
<?php get_footer(); ?>
Since your PHP is inside your code, you do not need the action attribute in your <form> tag. take action="#" out of the form tag and you should be good to go.
Right here:
<form class="standard-form base" method="post" action="#" enctype="multipart/form-data" id="dr_update_form" >
The action attribute is to send the data to another url and is why you get the # at the end of the current url.
something like this?
<input id="myButton" type="submit" value="<?php _e( 'Save Changes', $Directory_Core->text_domain ); ?>" name="update_listing">
<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
location.href = "www.yoursite.com/listings/edit-listing/";
};
</script>

Changed POST to GET. Now Ajax is returning multiple posts

When I used POST instead of GET for the call, it was taking a really long time for the wait. So, since I wasn't actually sending any data, I tried switching to GET. The speed increased a bit but now instead of grabbing the one post I need, it returns several posts. I'm guessing I need to alter the loop somehow in the function but I'm not sure what to do. Can someone help me out?
Call
$.ajax({
type: 'get',
url: ajaxURL,
data: {'action': 'load-content', post_id: post_id },
success: function(response) {
// Wait until all images are loaded
$('#project-container').html(response).imagesLoaded().then(function() {
// Fire again to rearrange the slide in the DOM
resize();
// Remove all 'hover' classes
$('article.project').removeClass('hover-sticky grayscale-sticky');
$('article.project img').removeClass('nohover');
// Remove the loading icon
$('.loading-icon').remove();
// If the user has scrolled...
if ($(window).scrollTop() !== 0) {
// First scroll the page to the top
$('html, body').animate({
scrollTop : 0
},400, function() {
matchContainerHeight();
projectStyles();
});
// If the user has not scrolled...
} else {
matchContainerHeight();
projectStyles();
}
return false;
});
}
});
Function
<?php
/**
* Ajax functions
*/
// Return the post content to the AJAX call
function my_load_ajax_content () {
$args = array(
'p' => $_POST['post_id'],
'post_type' => 'projects'
);
$post_query = new WP_Query( $args );
while( $post_query->have_posts() ) : $post_query->the_post(); ?>
<div class="post-container">
<div id="project-left-content">
<?php
the_title( '<h1 class="entry-title">', '</h1>' );
the_content();
if( get_field('client') ): ?>
<div class="client">
Client(s): <?php the_field('client'); ?>
</div>
<?php endif; ?>
<div class="project-cats">
<?php
$cat_names = wp_list_pluck( get_the_category(), 'cat_name');
echo join( ', ', $cat_names );
?>
</div>
<?php if( get_field('url') ): ?>
<div class="project-link">
<a class="first after" href="http://<?php the_field('url'); ?>" target="_blank"><?php the_field('url'); ?></a>
</div>
<?php endif; ?>
</div>
<div id="project-right-content">
<?php if( have_rows('slides') ): ?>
<div id="slider">
<!-- Slider Setup -->
<?php if( have_rows('slides') ):
$slideNumber = 0;
while ( have_rows('slides') ) : the_row();
$slideNumber++;
?>
<input type="radio" name="slider" id="slide<?php echo $slideNumber; ?>">
<?php endwhile;endif; ?>
<!-- Slide -->
<?php if( have_rows('slides') ): ?>
<div id="slides">
<div id="overflow">
<div class="inner">
<?php if( have_rows('slides') ):
while ( have_rows('slides') ) : the_row();
$slideImage = get_sub_field('slide_image');
?>
<article>
<img src="<?php echo $slideImage; ?>" alt="<?php the_title(); ?>">
</article>
<?php endwhile;endif; ?>
</div><!-- #inner -->
</div><!-- #overflow -->
</div><!-- #slides -->
<?php endif; ?>
<!-- Controls -->
<?php if( have_rows('slides') ):
$slideNumber = 0;
?>
<div id="active">
<?php while ( have_rows('slides') ) : the_row();
$slideNumber++;
?>
<label for="slide<?php echo $slideNumber; ?>"></label>
<?php endwhile; ?>
</div><!-- #active -->
<?php endif; ?>
</div><!-- #slider -->
<?php endif; ?>
</div><!-- #project-right-content -->
</div><!-- .post-container -->
<?php
endwhile;
wp_reset_postdata();
wp_die();
}
add_action ( 'wp_ajax_nopriv_load-content', 'my_load_ajax_content' ); // when the user is logged in
add_action ( 'wp_ajax_load-content', 'my_load_ajax_content' ); // when the user is not logged in
Change
$args = array(
'p' => $_POST['post_id'],
'post_type' => 'projects'
);
To
$args = array(
'p' => $_GET['post_id'],
'post_type' => 'projects'
);
as your ajax is GET and not POST anymore!

Categories

Resources