Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

andonovn on "jQuery can't select widget's AJAX appended HTML"

$
0
0

I am writing my first plugin and I am experiencing weird problem:

I am using shortcode to display front-end data and I have some DIV elements there that will trigger AJAX requests. The response from those requests is displayed in a widget. So far so good.
The response, however is also a HTML that contains DIV elements. And to some of them I want to apply AJAX requests on click. And this is not working.
However, if I put the exact same HTML content directly into the widget instead of using AJAX, it works. This is how I understood that jQuery can't select widget's AJAX appended HTML.
So far I tried:
- Putting my second ajax function as parameter to jQuery(document).ready() method
- Using jQuery find() method
- Loaded jQuery and my JS files in the footer (as explained in the codex)

PS I am using my ajax according to the codex and I think the problem is not there.
PS2 If you couldn't understand my case (I know I explained it in a bad way): I am trying to build something like shopping cart. I put the shopping cart as a widget and I am good adding products in it. The problem is that I can't now remove a single product from the cart because jQuery can't select the widget's appended HTML. But if I put a button to clear all products into the widget it works great.

Sorry for the long post, any help is appreciated :)


Abatap on "How to modify header data for admin pages?"

$
0
0

Hello. I need to remove one of the GET parameters from client's browser address bar to prevent duplicate operation. As far as I understand, the only way to do this server-side is to edit the Location header.

Here is a code snippet which is a part of an Order List page in WP Admin panel:

//display the contents of selected order
if (isset($_GET['show_order'])) {
    //see if our user clicked "mark this order processed"
    if (isset($_GET['mark_as_processed'])) {
      //update order status via custom function that uses $wpdb->update
      update_order($_GET['mark_as_processed'], 'Processed');

      //removing the mark_as_processed parameter from client's address bar
      //doesn't do anything
      add_action('send_headers', function() { header('Location: '.$_SERVER['HTTP_REFERER']); });
      //doesn't do anything either, probably because wp_headers isn't called for admin pages
      add_filter('wp_headers', function($headers) { $headers['Location'] = $_SERVER['HTTP_REFERER']; return $headers; });
      //wouldn't work too obviosuly
      header('Location: '.$_SERVER['HTTP_REFERER']);
    }
}

Can anyone tell me what is wrong with my approach? Note that the HTTP_REFERER global contains preciesly what I need in this situation so it's certainly not an issue here. The problem is that these add_filter or add_action functions don't seem to perform any sort of operation.

tsusanka on "Add link to the admin's "New" menu"

$
0
0

Is it possible to add a link to the New menu in top left corner?

Image here

Something like the add_menu_page() and add_submenu_page() but for the New menu.

dgcov on "Search for page by content"

$
0
0

I'm trying to find if a page exists and I'm using this clumsy code:

function searchPageContent($contents){
  $pages=new WP_Query( array('post_type'=>'page') );
  if($pages->have_posts()){
    while($pages->have_posts()){
      $pages->the_post();
      $PID=$pages->post->ID;
      $post=$pages->posts[0]->post_content;
      if(substr($post, 0, strlen($contents)) === $contents){
        return $PID;
      }
    }
  }
  return 0;
}

If the page exists which starts with the required content, it returns the Page ID.

This seems to work but is awfully clumsy.

Is there a better way?

jaime lauthier on "Replacing Adobe Flash with Html5 - .js and .css"

$
0
0

Hi all
I want to replace my Adobe flash page flip animation (soon to be discontinued I believe)

http://kitchenisus.com/recipe-book-form/

with an Html5 - . js - .css (script - code ?) that I managed to find.
Don't know much about coding.

Can anyone help
Regards

arayaz on "Filter category by tag"

$
0
0

I have this code that generates a dropdown list of tags to filter posts by on a category page.
How can I get the current tag slug on the generated page?

<?php function display_tags() {
	$tags = get_tags();
	if ($tags) {
		if (is_category( )) {
		echo single_tag_title('Currently browsing');;
		}

		echo '<p>Filter by: ';
		echo "<select onChange=\"document.location.href=this.options[this.selectedIndex].value;\">";
		echo "<option>Tags</option>\n";
		foreach ($tags as $tag) {
			echo "<option value=\"";
			echo "?tag=".$tag->slug;
			echo "\">".$tag->name."</option>\n";
		}
		echo "</select>";
		echo '</p>';
    }
}
display_tags();?>

Please help, I'm new at this.

longtran295 on "How to delete post if view-count y"

$
0
0

I want automatically delete post if after a period of time, the post view count is lower than a given number but i don't know more about php So i hope someone can help me!

Here is what i figured out:

[ Moderator note: Code fixed, please wrap code in backticks or use the code button. ]

function del_post($post_id=0)
{
	$count = 0;
	$post_id = !$post_id ? get_the_ID() : $post_id;
	if ($post_id) {
		$meta_count_key = 'my_views_count';
		$count = get_post_meta($post_id, $meta_count_key, true);
		if ($count == '') {
			delete_post_meta($post_id, $meta_count_key);
			add_post_meta($post_id, $meta_count_key, '0');
		}

		$count = intval($count);
	}

		if ($count < 10) {
        $post_date = strtotime($post->start_date);
        if(((time() - $post_date) > (7 * 24 * 60 * 60))) {
        wp_delete_post($post->ID);
        }
		}
}

mtupuschies on "Prevent Users from updating fields in profile"

$
0
0

Hi,

is there a way to change the permissions for editing the users profile?
I would like to have certain fields like "Display Name" only editable for the admins.

Thanks in advance!


everyeurocounts on "404 process"

$
0
0

Hi,

I am using pre_get_posts to modify the main query for CPT based on categories and meta queries, which works fine. But one issue, when no results are found, it uses a "no posts found" page (the standard one) rather than run the code on the archive page (i have code to deal with no posts found).

Is this set by the set up or is there a way to hook into the process to stop it pulling the 404 template

$args = array_merge(
                  // Default
                  array(
                  'label' => $plural,
                  'labels' => $labels,
                  'public' => true,
                  'show_ui' => true,
                  'supports' => array('title', 'editor'),
                  '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);

admiralchip on "How can I paginate search results from search in custom plugin and tables?"

$
0
0

I've been trying to get this done for hours now and it's just not working.

I have a custom plugin that has a search box on the front-end that one can use to search for data from my custom tables. (Please note that it doesn't have anything to do with searching posts.) The search works fine (I'm currently using the GET method if that makes any difference) and I'm able to get the correct results. However, I'm trying to add pagination to the search results but for some reason it's just not working. I tried following the answer that was given to this question by Hemi:

http://stackoverflow.com/questions/5322266/add-pagination-in-wordpress-admin-in-my-own-customized-plugin

To test it, I set the limit to 1 to see if it would work accordingly. However, instead of bring out 1 search result per page, it brings out 5 in the first page and none in the second page. I've also tried using the other solutions provided there but it still doesn't work. At first I thought it had something to do with not using get_results and num_rows properly but when I echoed the values I saw that they were correct. I've done something like this before in wordpress following a method similar to the one provided by Lawrence Cherone in the previous link without any problem so why this is not working properly is beyond me. Is there a correct wordpress way or style of paginating search results of a custom search that's in a custom plugin that doesn't have anything to do with posts?

Thanks in advance! I'll be really glad if someone could help me.

bobschwenkler on "Trouble adding inline JS in page content"

$
0
0

I'm having trouble with WP stripping JS from my page content. I'm wanting to use the following code as part of my Mailchimp opt in, and the JS is getting stripped. It works in preview mode but the moment I update the page the code disappears. I've been searching for over an hour for a solution and can't find one!

<input id="mce-FNAME" class="required" name="FNAME" type="text" value="First name" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/>

runzun on "I want contain locker at WooCommerce plugin is it possible?"

$
0
0

Am think you to use contain locker at Woocommerce plugin

example :

When user place order after filling there details.
I want facebook like to pop up blocking the contain.
I Want user to be able to processed only if the hit like button on facebook
Is it possible?

mmtf on "drop down menu on main page / issue"

$
0
0

Hello guys,

Newbie here I just learned how to modify my wordpress theme and unfortunately, I am lost...

I would like to add a drop down menu on my main page (not to the command bar).

Imagine that you have two buttons on the main page i.e. (professional) and (student). You click 1. (professional) 2. and a drop down menu is shown user can can filter his selection even more and select 3.(consultant) among (driver), (etc.). Is this doable using some plugins or should I make a PHP script? Any links,videos or advices appreciated.

Thanks a lot!

MT

CCDzine on "Apply $numpages to comment-page link"

$
0
0

I have comments on a standard post as normal and only on the last page of a paginated post ( <!--nextpage--> ). I managed to change the permalink of comments_link on index, home, archive, search to include $numpages in the URL, but I can't figure out how to do the same for next/previous_comments_link so that it says, for example, ...post/3/comment-page-2/#comments

I used the following for comments_link...

function pf_comments_link( $permalink, $post_id ) {

global $multipage, $numpages;

	if ( $multipage ) {
		$pfCommentURL = get_permalink();
		$pfCommentLinkAnchor = '/#comments';
		$pfCommentLink = $pfCommentURL.$numpages.$pfCommentLinkAnchor;}

	else {
		$pfCommentURL = get_permalink();
		$pfCommentLinkAnchor = '#comments';
		$pfCommentLink = $pfCommentURL.$pfCommentLinkAnchor;}

	return $pfCommentLink;
}
add_filter( 'get_comments_link', 'pf_comments_link', 10, 2 );

labm0nkey on "Cloning admin pages like users.php"

$
0
0

Hello,
In my project I want to make new menu position which will be actually a copy of 'Users' page but with some additional filters/modifications. For example as a result I need to have another menu position above users called "Admins" which will show exactly same structured page but with only Admin users. It is for better/easier user experience for my client.
My question is how to do this? I know that there are functions like add_menu_page but using them like this (users.php as identifier):
add_menu_page( 'custom menu title', 'custom menu', 'users.php', 'myplugin/myplugin-admin.php', '', plugins_url( 'myplugin/images/icon.png' ), 6 );
results in two menu positions which collapse and expand together, and I wanted them to work independly. I can also show content based on function but I don't know if there is any way to easly output content of whole users.php page?


vicstick on "Exclude a post category from the Older Posts count."

$
0
0

Hello, sorry if this is a repeat post - I've searched all over but can't find an answer to this. I'm hoping you can help!

I have managed to exclude an unwanted category of posts from my blog page - and also from the Recent Posts sidebar widget - by means of adding a couple of snippets of code that I found online to the bottom of my theme's functions.php file (I'll post the code I'm using below, in case it's useful).

However, the count in the Older Posts widget is now wrong - the excluded posts are still counted! You can see this at http://www.wymondhamukulelegroup.com/our-blog/

I'd like to amend the post count to exclude that category too. Can anyone point me in the right direction? I'd really appreciate it.

function remove_my_categories( $wp_query ) {
   //5= 'Tabs' category
 	$remove_cat = '-5';

	// remove from archives (except category archives), feeds, search, and home page
	if( is_home() || is_feed() || is_search() || ( is_archive() && !is_category() )) {
		set_query_var('cat', $remove_cat);
		//which is merely the more elegant way to write:
		//$wp_query->set('cat', '-' . $remove_cat);
	}
}

add_action('pre_get_posts', 'remove_my_categories' );

    /**
     * Recent_Posts widget w/ category exclude class
     * This allows specific Category IDs to be removed from the Sidebar Recent Posts list
     *
     */
    class WP_Widget_Recent_Posts_Exclude extends WP_Widget {

            function __construct() {
                    $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
                    parent::__construct('recent-posts', __('Recent Posts with Exclude'), $widget_ops);
                    $this->alt_option_name = 'widget_recent_entries';

                    add_action( 'save_post', array(&$this, 'flush_widget_cache') );
                    add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
                    add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
            }

            function widget($args, $instance) {
                    $cache = wp_cache_get('widget_recent_posts', 'widget');

                    if ( !is_array($cache) )
                            $cache = array();

                    if ( ! isset( $args['widget_id'] ) )
                            $args['widget_id'] = $this->id;

                    if ( isset( $cache[ $args['widget_id'] ] ) ) {
                            echo $cache[ $args['widget_id'] ];
                            return;
                    }

                    ob_start();
                    extract($args);

                    $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
                    if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
                            $number = 10;
                    $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];

                    $r = new WP_Query(array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'category__not_in' => explode(',', $exclude) ));
                    if ($r->have_posts()) :
    ?>
                    <?php //echo print_r(explode(',', $exclude)); ?>
                    <?php echo $before_widget; ?>
                    <?php if ( $title ) echo $before_title . $title . $after_title; ?>
                    <ul>
                    <?php  while ($r->have_posts()) : $r->the_post(); ?>
                    <li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
                    <?php endwhile; ?>
                    </ul>
                    <?php echo $after_widget; ?>
    <?php
                    // Reset the global $the_post as this query will have stomped on it
                    wp_reset_postdata();

                    endif;

                    $cache[$args['widget_id']] = ob_get_flush();
                    wp_cache_set('widget_recent_posts', $cache, 'widget');
            }

            function update( $new_instance, $old_instance ) {
                    $instance = $old_instance;
                    $instance['title'] = strip_tags($new_instance['title']);
                    $instance['number'] = (int) $new_instance['number'];
                    $instance['exclude'] = strip_tags( $new_instance['exclude'] );
                    $this->flush_widget_cache();

                    $alloptions = wp_cache_get( 'alloptions', 'options' );
                    if ( isset($alloptions['widget_recent_entries']) )
                            delete_option('widget_recent_entries');

                    return $instance;
            }

            function flush_widget_cache() {
                    wp_cache_delete('widget_recent_posts', 'widget');
            }

            function form( $instance ) {
                    $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
                    $number = isset($instance['number']) ? absint($instance['number']) : 5;
                    $exclude = esc_attr( $instance['exclude'] );
    ?>
                    <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
                    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>

                    <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
                    <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>

                    <p>
                            <label for="<?php echo $this->get_field_id('exclude'); ?>"><?php _e( 'Exclude Category(s):' ); ?></label> <input type="text" value="<?php echo $exclude; ?>" name="<?php echo $this->get_field_name('exclude'); ?>" id="<?php echo $this->get_field_id('exclude'); ?>" class="widefat" />
                            <br />
                            <small><?php _e( 'Category IDs, separated by commas.' ); ?></small>
                    </p>
    <?php
            }
    }

    function WP_Widget_Recent_Posts_Exclude_init() {
        unregister_widget('WP_Widget_Recent_Posts');
        register_widget('WP_Widget_Recent_Posts_Exclude');
    }

    add_action('widgets_init', 'WP_Widget_Recent_Posts_Exclude_init');

    ?>

Antony W. Serio on "invoking shortcode in post"

$
0
0

I am trying to get the hang of invoking shortcode in blog posts. I tried inserting <code>[display-posts tag="story" posts_per_page="20"]</code> at the start of a blog post. The first thing I noticed was that TinyMCE had conveniently bracketed my code with <p></p>. The end result was the text [display-posts tag=”story” posts_per_page=”20″] was inserted at the start of the post. I tried this both with and without the <code></code> brackets. Obviously I am doing something wrong. Is the display-posts shortcode currently included with the latest iteration of wordpress?

The blog that I am experimenting with is hosted locally on my home computer with MAMP.

sudeeptamrakar on "Website hacked by "+ADw-/title+AD4 HACKED BY TAG-1""

DeivCalviz on "How to display NextGEN featured image as nextgen thumbnail?"

$
0
0

I've tried using this:

<?php the_post_thumbnail( 'thumbnail' ); ?>

However, it displays a different thumbnail compared to the custom thumbnail I cropped for an image in Nextgen.

Basically, what I intend to do is to use the featured nextGEN image in the post and use the custom thumbnail version of it NOT the autocropped version that wordpress did..

Anyone? Thanks in advance.

dvalensi on "Make the last revision visible while the post is marked as pending?"

$
0
0

Hello,

I have been trying to solve this with the information I have found in the forum. However nothing has solved my problem. I am currently using the 'Revisionary' plugin for pending revisions, and although I've managed to avoid the 404 error, it only displays the title of the post and a blank page. I'd like that, while the post is pending revision, the last version before that modification is visible. Is this possible?

Thanks in advance!

Viewing all 8245 articles
Browse latest View live




Latest Images