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

cconoly on "Update Comment Count From Two Sources"

$
0
0

I have facebook comments and Wordpress comments enabled on my site. I also have a little comment counter for each post next to the title. I want the comment counter to display the total comments from both facebook comments and wordpress comments.

When a facebook comment is made I count both the wordpress comments and facebook comments and update the comment count under the post in the DB with a custom function outside of wordpress. That works great...

My problem is that when a new wordpress comment is made, it calls wp_update_comment_count which only counts the comments from wordpress.

I could, but do not want to, edit a core file. I could change the wp_update_comment_count function to count all the comments like I do after a facebook comment is made, but I don't like editing core files.

Is there a filter or hook I could use after the wordpress counting that I could use to call my own counting function and update the DB with the total comments? Or is there a way to override that function through my theme?

thanks in advance!


Trialstyle98 on "Template for Video-Playlist ( as custom post & Custom taxonomy)"

$
0
0

Hey Guys,
I would like to add videos from my Youtube channel to my blog.
Therefore, I made an custom Post Type "Videos" and a Taxonomy called "playlist" with the help of "Types".
Now I want to customize the site of the single taxonomies (taxonomy-playlist.php).
I would like to have the current Video displayed on the left side and on the right side (In the Sidebar) a list with all the content(Videos) in my playlist, like on https://gopro.com/channel/
First I tried it with an html list, but that does not really work.
Does anyone have better ideas how to realize this?

Here is my current code:

<?php get_header(); ?>

	<?php do_action( 'colormag_before_body_content' ); ?>

	<div id="primary">
		<div id="content" class="clearfix">

			<?php while ( have_posts() ) : the_post(); ?>

				<?php
					if (get_the_id() == $_GET['Videos']) {
						the_title();
						echo types_render_field( "video", array('raw' => false) );
					}
				?>

			<?php endwhile; ?>

		</div><!-- #content -->

	</div><!-- #primary -->

	<div id="secondary">
		<div id="sidebar" class="clearfix">
			<?php rewind_posts(); ?>

			<form action="<?php echo $_SERVER['PHP_SELF'] ?>">
				<select name="Videos" size="8" onchange="this.form.submit()">
					<?php if ( have_posts() ) : the_post(); ?>
						<option selected value="<?php get_the_id() ?>"> <?php the_post_thumbnail('playlist-video-thumbnail') ?> <?php the_title() ?></option>
					<?php endif; ?>

					<?php while ( have_posts() ) : the_post(); ?>
						<option value="<?php get_the_id() ?>"> <?php the_post_thumbnail('playlist-video-thumbnail') ?> <?php the_title() ?></option>
					<?php endwhile; ?>
				</select>
			</form>

		</div>
	</div>

	<?php do_action( 'colormag_after_body_content' ); ?>

<?php get_footer(); ?>

I know, this can´t work. But I hope that you understand what I want to do and can help me.

David Gewirtz on "Is there GUID or UUID JavaScript function already in WP?"

$
0
0

I need to generate a universally unique code for each transaction and I'm considering using node-uuid (at https://github.com/broofa/node-uuid), but then realized there's a good chance there's something already included in WordPress. It needs to be accessible client-side for non-logged-in users.

Alternatively, what's the safest way to distribute and include the .js file that comes with node-uuid so it doesn't conflict with other installs?

Thanks
David

bacherj on "Attempted to create a widget plugin, but now it only displays -1"

$
0
0

Hi,
I attempted to create a plugin that would allow an admin to choose what type of content they want on the front page.

In the backend editor when I drag the widget to a sidebar, it displays the form for a second, displays -1. The widget then does not save. I suspect it has something to do with the widget being registered, but I am not sure. My code is below. If you can help me, that would be greatly appreciated.

<?php
/*
Plugin Name: cns-widget-plugin2
Plugin URI: lehmow2.com
Description: This plugin will create widgets for different categories on the front page
Version: 0.0.0.2
Author: Jacob Bacher
Author URI: github.com/jbacher
License: LMAO idk who uses this. Just pls say it was Jacob Bacher who originally made it, k thanks.
*/
?>

<?php
  require_once ABSPATH . 'wp-content/themes/JointsWP-CSS-master/functions.php';

  class Front_Page_Widget extends WP_Widget {

    function __construct() {
      $widget_ops = array(
        'classname' => 'Front_Page_Widget',
        'description' => 'Widget for picking out front page content'
      );
      parent::__construct('Front_Page_Widget','Front Page Widget',$widget_ops);
    }

    function form($instance) {
        $categories_arr = get_categories();
        $tags_arr = get_tags();

      ?>
      <script>
      </script>
      <?php
      if ($instance) {
        $title = esc_attr($instance['title']);
        $select = esc_attr($instance['select']);
        // $radio_choice = esc_attr($instance['radio_choice']);
      } else {
        $title = '';
        $select = '';
        // $radio_choice = '';
      }
      ?>
      <p> <!-- widget title -->
        <label for="<?php echo $this->get_field_id('title'); ?>"><?php
        _e('Title:', 'cns-widget-plugin2'); ?> </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>

      <?php
      ?>
      <!-- dropdown-->
      <br />
      <label for="<?php echo $this->get_field_id('select'); ?>"><?php
      _e('Select:', 'cns-widget-plugin2'); ?> </label>

      <form action="" method="post">
        <input type="radio" name="radio1" value="category">Categories</input>
        <input type="radio" name="radio2" value="tag">Tags</input>
      </form>

      <select name="<?php echo $this->get_field_name('select');?>"
              id="<?php echo $this->get_field_id('select'); ?>"
              class="widefat">

        <?php

          foreach ($categories_arr as $category) {
            $val = $select == $category->name ? 'selected="selected"' : '';
            echo '<option value = "'.$category->name.'"
                  id="'."select-category-".$category->term_id.'"'.$val.'
                  >'.$category->name.'</option>';
          }
          foreach ($tags_arr as  $category) {
            $val = $select == $category->name ? 'selected="selected"' : '';
            echo '<option value = "'.$category->name.'"
                  id="'."select-tag-".$category->term_id.'"'.$val.'
                  >'.$category->name.'</option>';
          }
        ?>
      </select>
      <script>
      </script>
      <?php
    }

    function update($new_instance, $old_instance) {
      echo "<h1>hi</h1>";
      $instance = array();
      $instance['title'] = strip_tags($new_instance['title']);
      $instance['select'] = strip_tags($new_instance['select']);
      // $instance['radio_choice'] = strip_tags($new_instance['radio_choice']);
      return $instance;
    }
    //widget display, this s what the user will see
    function widget($args, $instance) {
      extract($args);
      //these are the widget optionsgf
      $title = apply_filters('widget_title', $instance['title']);
      $select = $instance['select'];
      echo $before_widget;
      //display the widget
      echo '<div class="widget-text wp_widget_plugin_box">';
      //check if title is set
      if ($title) {
        echo $before_title . $title . $after_title;
      }
      if ($select) {
        echo $select . ' is selected';
      }
      echo '</div>';
      echo $after_widget;
    }
  }
//register widget
function register_my_widget(){
  register_widget('Front_Page_Widget');
}

add_action('widgets_init','register_my_widget');
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
  var select = $('#widget-Front_Page_Widget-2-select'),
      options = select.find('option');

  $('[type="radio"]').click(function() {
    var text = $(this).val();
    var visibleItems = options.filter(
      function(index, element) {
        return element.id.indexOf(text) > -1});
    console.log("changing visible items");
    console.log(visibleItems);
    options.not(visibleItems).hide();
    visibleItems.show();
  })
})
</script>

CoBu1 on "Querying multiple post types with different post statuses"

$
0
0

Here is my WP_Query object:

$ls_any_posts = new WP_Query(
		array(
			'post_type'       => array('post', 'event', 'deal', 'contest', 'partner'),
			'posts_per_page'  => 5,
			'meta_query'      => array(
		            array(
		                'key'     => 'whats_hot',
		                'value'   => 1,
		                'compare' => '=',
		            )
	                ),
	                'post_status'     => array('publish', 'future'),
	       )
	);

Currently, this queries for all my custom post types that have a status of Publish or Future.

Instead, I only want to query "Future" posts if the post type is "Event". If it's one of the other post types, the status must be "Publish".

How could I accomplish that?

Bento4Extend on "Update for my plugin not showing as available"

mmkml on "Exlude category from get_the_category_list"

$
0
0

Greetings.

Can I somehow modify wp-includes/category-template.php function (wp-includes/category-template.php) in its code to permanently hide/exclude one of categories from displaying by it?

Soultions found in the web or plugins are not working.

Thanks in advance.

Stefano Toria on "Changing the Way "Twenty Sixteen" displays Site Title"

$
0
0

I am cross-posting to both "Themes and Templates" and "Plugins and Hacks".

I am developing a child theme of Twenty Sixteen, so far I've had no problems.

I want to display an image instead of the "Site Title" text (Appearance > Customise > Site Identity > Site Title)

I have tried the obvious way of inserting an HTML tag of <img> as the Site Title text, but somewhere in the processing of this element either the theme or WordPress itself "sterilise" tags by switching the "<" and ">" to "& lt ;" and "& gt ;" respectively.

I want to disable this function, at least for the Site Title.

(I am an old hand at writing code, having started back in 1973; I am not much up-to-date with PHP and it would take me quite a while to figure this thing out by myself, so I would be most grateful to anybody in the community who can help this old man around this small hurdle).

Stefano Toria, stefano@musivarte.ch


thebirdfly on "Use press this as a frontend popup for users to submit there own posts?"

$
0
0

Hi I have been looking around for good frontend posters however wordpress has already got pressthis added to the core of it anyway and I was hoping that there is a simple way fr me to add pressthis editor as a popup in my menu that opens up for logged in users and allows them to make posts. Im trying my best to try and make something like medium.com were users dont see wordpress dashboard.

thanks.

Miflon on "Unexpected display caracter"

$
0
0

Hy every body,

My actual configuration
- WordPress Version : 4.4.2
- PHP/MySQL Version de : 7.0.3/5.6.28
- My theme : TheNews 2.0 (Flexithemes)
- Plugins : All In One WP Security 4.0.6 / Contact Form 7 4.4 / really Simple Captcha 1.8.0.1 / WordPress File Upload 3.7.3
- Web hosting : o2switch
- Site address: ucrives.fr

The problem : I work on a localhost. When I activate a plugin of my own, I receive that warning:
The plugin has generated 3 unexpected display caracters during activation. If you see a message "headers already sent" ...
I not sure of my translation! Despite having that message, my plugin works fine.

Please, can you tell me what is going wrong, Michel.

Pierre-Yves on "Port sort order on archive"

$
0
0

Hi there,

I need to sort post when displaying with archive page.
I want post in randomize order except some which are market as "partner". These must be displayed first.

I don't know how to do that.

Using custom field or taxonomy ?

Thanks for your help.

pixelstud on "Hide post titles, so only the thumbnail links to the permalink"

$
0
0

Is there a way to hide post titles, so only the thumbnail links to the permalink (with title, full image, post etc.)? Is there a way to do this globally and/or per post?

I'd like to have just a grid of thumbnail images as links to posts, instead of the more common title and thumbnail. The titles in my case are hashtags.

-> http://www.pixelstud.com

PS
I was able to find a way, In functions.php to link all post thumbnails to the permalink using:

// THIS LINKS THE THUMBNAIL TO THE POST PERMALINK

`add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );

function my_post_image_html( $html, $post_id, $post_image_id ) {

$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>';

return $html;
}`

Any ideas would be appreciated!
Jayson

cueson1224 on "My site got hacked, not recover after I delete all the files"

$
0
0

Hi guys, I need help on site http://www.jiakaosou.com

I am a beginner in wordpress. My site got hacked (redirect to another site) yesterday and I tried to clear all the files in File Manager, it recovered a moment. However, after I reinstall the Wordpress, after a few hours my site got hacked again (this time you can see my site has been modified). I tried to clear all the files again but the site stays the same.

Please help me have a look and if you have any advice on it, please let me know.

Thank you very much guys in advance.

shareef300 on "ERROR"

rashu123 on "Error : PHP Warning: Invalid argument supplied for foreach() in G:\PleskVhosts"

$
0
0

<div class="meta-box-sortables col-lg-12">
<div id="fv_votes_workplace" class="postbox ">
<div id="box-vote-settings" class="handlediv" title="Нажмите, чтобы переключить">
</div>
<h3 class="hndle"><span><?php echo __('Design / social settings', 'fv') ?></span></h3>
<div class="inside">
<div id="sv_wrapper">

<fieldset>
<div class="row">
<div class="form-group col-sm-8">
<label><i class="fvicon fvicon-share"></i> <?php echo __('Title contest for soc. networks ', 'fv') ?>
<?php fv_get_tooltip_code(__('*name* will be replaced by name of the contestant.
Only works for Vkontakte, Twitter and Pinterest,
others socials take title from title page.

If not specified - the name of the contestant taken', 'fv')) ?>
</label>
<input type="text" name="fv_social_title" class="form-control" value="<?php echo ($action == 'add') ? '' : stripcslashes($contest->soc_title) ?>">
</div>
<div class="form-group col-sm-8">
<label><?php echo __('Description contest for soc. networks', 'fv') ?>
<?php fv_get_tooltip_code(__('*name* will be replaced by name of the contestant.
Only works for Vkontakte and Twitter
take the rest of the description of the description page.

If not specified - soc. networks use at its discretion', 'fv')) ?>
</label>
<input type="text" name="fv_social_descr" class="form-control" value="<?php echo ($action == 'add') ? '' : stripcslashes($contest->soc_description) ?>">
</div><!-- .misc-pub-section -->

<div class="form-group col-sm-8">
<label><?php echo __('Picture for social networks', 'fv') ?>
<?php fv_get_tooltip_code(__('Only works for Vkontakte and Pinterest.

If not specified - is taken from field Image', 'fv')) ?>
</label>
<input type="text" name="fv_social_photo" class="form-control" value="<?php echo ($action == 'add') ? '' : $contest->soc_picture ?>">
</div><!-- .misc-pub-section -->

</div>

<div class="row">
<div class="form-group col-sm-8">
<label for="fv_timer">
<i class="fvicon fvicon-stopwatch"></i> </span><?php echo __('Timer', 'fv') ?>
<?php fv_get_tooltip_code(__('If you want show countdown timer, check this option', 'fv')) ?>
</label>
<select id="fv_timer" name="fv_timer" class="form-control">
<option value="no" <?php ( isset($contest->id) )? selected('no', $contest->timer) : ''?>> <?php _e('No show', 'fv') ?></option>
<?php foreach ($countdowns as $key => $countdown_title): ?>
<option value="<?php echo $key ?>" <?php ( isset($contest->id) )? selected($key, $contest->timer): ''; ?>><?php echo $countdown_title ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-sm-8">
<label for="lightbox_theme"><?php echo __('Lightbox theme', 'fv'); ?></label>
<select id="lightbox_theme" name="lightbox_theme" class="form-control">
<?php foreach (FvFunctions::getLightboxArr() as $lightbox => $theme_title): ?>
<option value="<?php echo $lightbox ?>" <?php ( isset($contest->id) )? selected($lightbox, $contest->lightbox_theme): '' ?>><?php echo $theme_title ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-sm-8">
<label for="sorting"><?php echo __('Photos order', 'fv'); ?> <?php fv_get_tooltip_code(__('Output order of pictures on the page', 'fv')) ?></label>
<select id="sorting" name="sorting" class="form-control">
<?php foreach (fv_get_sotring_types_arr() as $key => $sort_title): ?>
<option value="<?php echo $key ?>" <?php ( isset($contest->id) )? selected($key, $contest->sorting): ''; ?>><?php echo $sort_title ?></option>
<?php endforeach; ?>
</select>
</div>
</div>

<div class="form-group">
<label>
<input type="checkbox" name="show_leaders" <?php echo ($action == 'add' || !$contest->show_leaders) ? '' : 'checked' ?>>
<?php echo __('Show leaders block', 'fv'); ?>
</label>
<small>(This option will show Leaders block above contest photos. Yuo can also use leaders Shortcode and off this option for show Leaders in other place/page.
" target="_blank">More settings here)</small>
</div>

<div class="clear"></div>

</fieldset>

</div>
</div>
</div>
</div>


plusless on "Checkbox selection for Taxonomy terms"

$
0
0

Hi everbody,

I created a new ‘gender’ taxonomy, for which I automatically registered the terms ‘men’ and ‘women’. For this new taxonomy I needed to create a custom metabox with checkboxes for every term of the gender taxonomy because of the user experience (the option to choose a gender (or multiple) for each post is very important for the site I’m working on, so it has to be quick and easy to do).

This is all working just fine (code below), but I can’t seem to find a way to save the settings from the checkboxes. I’ve tried many things, eventually I got it working with ‘tax_input[gender][]’ but with the massive drawback that when editing the post you can’t uncheck all checkboxes because that won't save the new setting. Thats because unchecked checkboxes do not send any data to the $_POST event.

So I’ve tried to create a save function hooked into ‘save_post’ (code below), but so far that didn’t work out. Does anybody have a idea how to make this work?, thanks in advance.

— Wessel

The codes:

- Metabox callback:
Echo's all terms registered for the 'gender' taxonomy (this works except saving the settings)

function meta_gender_callback($post) {
	wp_nonce_field(basename(__FILE__), 'meta_gender_nonce');

	// All terms:
	$gender_terms = get_terms('gender', 'hide_empty=0');
	// All terms currently assigned to the post:
	$post_terms = wp_get_object_terms($post->ID, 'gender');

	// All terms currently assigned to the post inside an array:
	$current_terms = array();
	if ($post_terms) {
		foreach ($post_terms as $post_term) {
			$current_terms[] = $post_term->term_id;
		}
	}

	// Echo list:
	echo('<ul>');
	foreach ($gender_terms as $term) {
		if (in_array($term->term_id, $current_terms)) {
			echo('<li id="gender-'.$term->term_id.'">
					<label>
						<input value="'.$term->slug.'" type="checkbox" id="in-gender-'.$term->term_id.'" name="gender-data[]" checked="checked" />'.$term->name.'
					</label>
				</li>');
		} else {
			echo('<li id="gender-'.$term->term_id.'">
					<label>
						<input value="'.$term->slug.'" type="checkbox" id="in-gender-'.$term->term_id.'" name="gender-data[]" />'.$term->name.'
					</label>
				</li>');
		}
	}
	echo('</ul>');
}

- Saving function (this does NOT work):
First does some default checks and then tries to save the new settings set by the checkboxes

function save_meta_gender($post_id, $post, $update) {
	if (!isset( $_POST['meta_gender_nonce'] ) || !wp_verify_nonce( $_POST['meta_gender_nonce'], basename( __FILE__ ) ) ){
		return;
	}

	if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
		return;
	}

	if (!current_user_can( 'edit_post', $post_id ) ){
		return;
	}

	if (isset($_POST['gender-data'])) {
		$gender_data = $_POST['gender-data'];
		wp_set_object_terms($post_id, $gender_data, 'gender' );
	}

}

add_action('save_post', 'save_meta_gender', 10, 3);

webinclusion1 on "Importing records to wp_posts generates 404s only on one custom-post-type"

$
0
0

I have written an app for my client which will sync product records in their SQL Db with the wp_posts and wp_postmeta of their wordpress site. Adding new or updating existing accordingly.

The app scrolls through recently modified/added records in the SQL tables to update or create new custom post types in the wp_posts table, and then generates/modifies wp_postmeta records with the same post_id to populate the custom fields for each one.

The post_type field of wp_posts is given the slug of its custom post type according to which product-type is being imported. Each product type has its own CPT.

The same function in the App is used to import all threee custom post types. When called, it is passed the post-type variable so that field can be filled. The first and the third product-types work perfectly. However, when the second one is saved (post_status = 'publish'), its permalink renders the 404 page...

All three post-types were created using the WP-Types plugin. All three have the setting 'rewrite permalinks' checked with the option 'use the normal WordPress logic' selected.

So my questions are:

1. What should I look for in the code which might be preventing the permalink from opening the page?

2. At what stage is the url of a post generated, and where is it stored? The guid field is for attachments and other references, is it not? and not for the post URL.

3. When researching for a solution I read about the importance of the .htaccess file config in generating urls. There isn't one in the client's (highly secure) live site, but there is on the test site. But we experience the same problem on both. And that wouldn't explain why WordPress is creating good posts (without 404s) for two post-types, but not the third.

Can anyone suggest what we need to identify to learn how to fix this? I'm scratching my head to understand why, when the same function (with the only difference being the post-type-slug variable in its arguments) imports all three post-types' posts, two CPTs import perfectly, but one does not.

Thank you

seomen123 on "Remove shortcode"

ah4kh on "site open when i try open my site"

echapp on "Remove section "You are previewing ..."from customizer"

$
0
0

Hi,

I'd like to remove the "You are previewing bloginfo('name')" section/panel in customizer...

Looks like this section/panel it's not like the others that you can remove using $wp_customize->remove_section('$id'), there's no reference of it in class-wp-customize-manager.php

Does Anybody know a way to remove that section/panel from customizer?

tks

Viewing all 8245 articles
Browse latest View live




Latest Images