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

alanitech on "Programattically create post from outside wordpress"

$
0
0

Hi!

I have a wordpress blog at mydomain.com/wordpress/wp-admin
I have a separate web app at mydomain.com/secure-authentication/stuff

I want to provide a tool at that separate webapp that (effectively) triggers wp_insert_post & add_post_meta over at the wordpress app. (Or if not actually using wp_insert_post, somehow or another inserts a post to wordpress.)

This isn't a plugin, since it's running outside of wordpress; there's no action to hook on to.
Maybe xmlrpc.php is my answer?

Any docs or examples to get me started?


emaneric on "Need to replace IP address with FQDN in WP database"

$
0
0

Due to circumstances beyond my control, I had to build a WP web site in the public folder of a hosting account that could only be accessed by it's IP address rather than a fully qualified domain name (FQDN). The intended FQDN has now been pointed to the IP address and successfully resolves to the home page however all subsequent pages, posts, images, documents etc. continue to link through the IP address as one would expect.

If possible I would like to do a global search and replace through the WP database (MySQL) and substite the FQDN for the IP address rather than try to edit all of the posts, pages, links, etc. in the WP backend.

Is there a step by step process to accomplish this? (I rarely tinker direct to the WP database.) I trust some changes would also be necessary in the htaccess files and wp-config file. Or maybe some kind of redirect in the htaccess file(s) could make the FQDN appear rather than the IP address to the outside world.

The site is at http://www.staugpres.org.

Please advise.

Thank you.

Eric

Saeed Salam on "How to display an ad after a number of post in homepage?"

$
0
0

Hello,

I have been searching for a way to display ads in my homepage. my homepage have 20 posts. and i want to show an ad just after 10th post. i got a code to add ads after every 10th post, but i only want to show an ad after the 10th post. don't want to repeat it.

can someone help me on this?

thanks
Saeed

VOST on "Repeatable fields with dropdown lists of taxonomies' terms"

$
0
0

Hello,

I am trying to put in place repeatable fields with drop-down lists containing terms from custom taxonomies. It is displayed beneath the editor field in one of my custom post type.

Here is what I cannot achieve:

  • simply return the html for the drop-down lists (works fine when I try with inputs for example)
  • attribute values to dynamic options

In the end I got the 'Add a screening' (equal to "Add new field") button but when I click on it nothing happens; none of the fields appear.

My code is in the function.php file. This is the first part of the code with the drop-down lists which seems to cause me trouble - it was obtained more from tweaks of numerous copy and paste than from my little knowledge of php:

function print_screening_field($cnt, $p = null) {
if ($p === null) {
    $a = $b = '';
} else {
	    $a = $p['screeningName'];
	    $b = $p['screeningCountry'];

	    $festivalterms = get_terms('festival', 'hide_empty=0');
	    $countryterms = get_terms('country', 'hide_empty=0');

	        $html = '';
	        $html .= '<li>';

		$html .= '<label>Screening: </label>';
		$html .= '<select>';
		foreach ($festivalterms as $term) {
			$html .= '<option>';
			$html .= $term->name;
			$html .= '</option>';
		}
		$html .= '</select>';

		$html .= '<label>Country: </label>';
		$html .= '<select>';
		foreach ($countryterms as $term) {
			$html .= '<option>';
			$html .= $term->name;
			$html .= '</option>';
		}
		$html .= '</select>';
    	$html .= '<button class="remove">Remove</button>';
    	$html .= '</li>';
	}
	return $html;
}

This is the second part of the code; the meta box part with jQuery:

function screening_details_meta_box(){
	global $post;
	$custom = get_post_custom($post->ID);
  	$data = get_post_meta($post->ID,"screeningDetails",true);
?>

  	<h4>OTHER SCREENINGS</h4>
  	<?php
  	echo '<ul id="data_items">';
  	$d = 0;
    	if (count($data) > 0){
    	    foreach((array)$data as $p ){
    	        if ( isset($p['screeningName']) || isset($p['screeningCountry']) ){
    	            echo print_screening_field($d,$p);
    	            $d = $d +1;
    	        }
    	    }
	    }
	echo '</ul>';
   	?>
    <span id="here"></span>
    <button class="add"><?php echo __('Add a screening'); ?></button>
    <script>
    	var $ =jQuery.noConflict();
    	$(document).ready(function() {
    	var count = <?php echo $d; ?>;
    	$(".add").click(function() {
        	count = count + 1;
        		$('#data_items').append('<? echo implode('',explode("\n",print_screening_field('count'))); ?>'.replace(/count/g, count));
        			return false;
        		});
        		$(".remove").live('click', function() {
        			$(this).parent().remove();
        		});
        	});
    </script>
    <style>#data_items {list-style: none;}</style>
    <?php
}

As in case I don't find a solution, I can use the following piece of code with the screening_details_meta_box function (the one that contains the jQuery bit). But it means I am loosing the drop-down lists:

function print_screening_field($cnt, $p = null) {
if ($p === null){
    $a = $b = '';
} else {
    $a = $p['screeningName'];
    $b = $p['screeningCountry'];

    $festivalterms = get_terms('festival', 'hide_empty=0');
    $countryterms = get_terms('country', 'hide_empty=0');
}
return  <<<HTML
<li>
    <label>Screening:</label>
    <input type="text" name="screeningDetails[$cnt][screeningName]" value="$a"/>

    <label>Country:</label>
    <input type="text" name="screeningDetails[$cnt][screeningCountry]" value="$b"/>

    <button class="remove">Remove</button>
</li>
HTML
;
}

I would like to avoid any plugins. If you could simply mention the technical and exact terms describing what I am trying to do, it would be helping me in my research already.

Thank you

Francesca_M on "post_id to javascript var"

$
0
0

Hi,
I'm looking for some help:
I need, when the user click on 'read more', to save the post id in a javascript var.

If i use:

<div id="post-<?php the_ID(); ?>">
<script type='text/javascript'>
	<?php
	$num_post="post-".get_the_ID();
	echo "var selected_post='$num_post";
	?>
	</script>

[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

the code write the right var for every post, but if I try to use it, I always have the id of the last post of the page. How can I save only the necessary var?

Ailsa Craig on "Custom page at bottom of normal page shortcode"

$
0
0

Hi,
Trying to get a page to appear below a normal page via shortcode - code below works for inserting a 'page' below a 'page' but how would I alter the code to intsert a 'custom post typ' below a page. Anybody any ideas?

Here's the code I'm trying to alter:

/**
 * Create a shortcode to insert content of a page of specified ID
 *
 * @param    array        attributes of shortcode
 * @return     string        $output        Content of page specified, if no page id specified output = null
 */
function pa_insertPage($atts, $content = null) {
 // Default output if no pageid given
 $output = NULL;

 // extract atts and assign to array
 extract(shortcode_atts(array(
 "page" => '' // default value could be placed here
 ), $atts));

 // if a page id is specified, then run query
 if (!empty($page)) {
 $pageContent = new WP_query();
 $pageContent->query(array('page_id' => $page));
 while ($pageContent->have_posts()) : $pageContent->the_post();
 // assign the content to $output
 $output = get_the_content();
 endwhile;
 }

 return $output;
}
add_shortcode('pa_insert', 'pa_insertPage');

[Moderator Note: Please post code & markup between backticks (not single quotes) or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

robtheboss12 on "Have Users enter a current username to register"

$
0
0

I'm currently creating a site that only allow a user to register for the website only if they input the username of a current member. If the new user do not input the correct username. They will not be able to sign up... The section a user will have to enter a current member username would be called sponsor name.

I will like signup page to look let this

Username (require) :___________
Sponsor Username (require):__________
Email Address (require) _____________
Choose a Password (require)___________
Confirm a Password (require)__________

viperfunk on "Here's a problem"

$
0
0

I have a wordpress site with posts that have links to a custom php script (watermarking.php).

The links look like: mysite.com/watermarking.php?file=blah&user=email@foo.com

My watermarking script then uses the file and user GET values to generate a PDF file for download with each page watermarked with the users email (works, tested.)

Problem is, when the script is in place and I click a link I simply get a "No Access" image. :( If I strip out the GET values form the link and just output some "Hello World" message, the link works just fine. How can I force wordpress to stop freaking out whe I pass some GET variables to my custom script?


sem101 on "What's best practice for theme/plugin settings API for new dev?"

$
0
0

Hi, I'm new to theme & plugin dev, go easy on me :)

There are 3 specific areas I'm trying to wrap my head around and understand what WP is trying to do with future releases, and how should I begin coding to these standards.

(I will soon start following the blog, irc, news, trac, etc. thanks.)

Theme settings/options:

A) Theme Customization API (Customize)
B) Settings API (Settings)
C) Plugin API (Appearance)

See why I'm confused? There are 3 areas I can implement settings/options. My first stab was to go after Customize. So I began coding and put ALL of my settings/options in there. Looks/works great! However, when I started to dev a few plugins, I had a look at B & C above and realized that these are great places to put ALL my settings as well.

So I have a ton of completed settings in Customize, but do you think I should put my settings in Settings or Appearance?

At first thought, I was thinking Customize would be solely for Front-End styling: Background Image, Logo, Fonts?

Then use Settings API for things like: if checked() locate_template(ACTIVATE_CUSTOM_PLUGIN)?

What do you guys think and what does WP want me to do for future standards?

Thanks WP peeps!

techofweb on "How to set permalinks as incremental integer values"

$
0
0

Hi...
What I want is that the permalinks of my posts should be
http://www.domain.com/71
domain.com/72
domain.com/73

Whenever I add a new post, it should show the url of post with +1 added integer and I should have the option to set any different numeric value for any post

Is there any hack, plugin or any solution for the same

Thanks a lot

asterbird on "show only authors posts with custom fields in admin"

Robert.Vidrine on "Please explain Theme Customization setting default value"

$
0
0

I was very excited in 3.4 to see the Theme Customization come about, and have read a ton of stuff about it (including the OttoPress posts). I wrote a bunch of customizations for my theme, which will greatly add to the functionality and remove the need for most people to write any CSS or PHP at all. However, when I started testing it out on installs that had never set the specific theme mods before (I'm using theme_mod instead of option), I realized that the defaults I defined in the add_setting statement were not getting used at all. (I know that I could define the default directly in the get_theme_mod( 'modname', mydefaultvalue); but that defeats the purpose of defining the default in the add_setting.

I just re-read the Theme Customization API documentation in the codex, and noticed something in one of Otto's comments I hadn't noticed again. Next to one of the defaults defined in his add_setting example it says "//Default setting/value to save".

This makes me think that I've been misunderstanding completely how the default works. Should this be passed to get_theme_mod( 'somemod'); if somemod isn't set in the theme mods, or is it just the default value that will be saved if ome saves the theme customizer without entering a value? (I'm hoping that the default value will be used if somemod isn't saved in the database, but a default is defined in the add_setting, so the default will work even before they save the Theme Customizer.)

Do I just need to pass the default during each get_theme_mod call, even though it's defined in the add_setting?

pjbursnall on "Remove theme options link from admin bar"

$
0
0

Hi,

I am customising an admin panel for a client, using the AG Custom Admin plugin. The only thing I can't disable is the theme options link which sits to the left of 'New' link (for post, media, page) on the admin bar. How can I hide this?

I know I could disable the admin bar but I'd rather just remove the theme options link.

Thanks,
Paul.

jmlmj on "How to make comments invisible for specific users"

$
0
0

Hi there,

I'm new to the wordpress world and I'm interested in comment visibility.

For example, I would like to do the following:

1. comments created by <user> are only visible to <user> and also specifically defined admin users (admin group).
2. comments by <user> can be aggregated into one place when specific admin users log in (maybe there's a special plugin for this)?

I'm posting these two questions in 'hacks' because I am not sure if this is a situation in which I need to modify my theme into a custom theme, or if it is a situation that has been solved by particular plugins already.

Thanks for any advice!
jml

KarinMA on "Changing the loop"

$
0
0

Hi!

I have the code below that is set to pick up different cathegories. How can I change it to only search for category id=81 for example? I have tried different possibilities but can´t get this to work...

Thanks
/Karin

[please mark any posted code - http://codex.wordpress.org/Forum_Welcome#Posting_Code - the code below is partially broken by the forum parser]

<?php $current_num = $wp_query->current_post + 1; ?>

<?php if ( $wp_query->current_post == 0 ) {
	echo '
<li><ul class="shop-block-list">';
} elseif ( $wp_query->current_post % 3 == 0 ) {
	echo '</li>
<li><ul class="shop-block-list">';
} ?>

<li id="post-<?php the_ID(); ?>" <?php post_class("clearfix"); ?>>

	<div class="shop-block-img-wrapper">

		<?php if( has_post_thumbnail() ) { ?>
			<a>" rel="bookmark" title="<?php the_title_attribute(); ?>">
				<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'image-style3' ); ?>
				<?php echo '<img src="' . $src[0] . '" alt="" />'; ?>
			</a>

		<?php } else { ?>
			<a>" rel="bookmark" title="<?php the_title_attribute(); ?>">
				<?php echo '<img src="' . get_template_directory_uri() . '/images/image2.png" alt="" />'; ?>
			</a>
		<?php } ?>

	</div>

	<h4><a>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>

</li>
<?php if ( $current_num % 3 == 0 ) {
	echo '';
} elseif ( $current_num == $wp_query->post_count ) {
	echo '';
} else {
	//echo '';
} ?>

dealfiles on "Exclude admin from custom function"

$
0
0

I took over a WP site that was developed by another person. They created a custom function in functions.php named wp_authors_directory (see code below). They then created a page template to display the results of the function (see code below).

The problem is, it appears to me as though the function is designed to exclude the admin from the directory, but the admin is not being excluded. Both the user name and the nickname of the admin are "admin" but it is still not being excluded. Can someone help?

Here is a link to the directory page where the results are rendered, admin is displaying at the top:

http://networkoftacoma.com/member-directory/

Very much appreciated!

functions.php code:

function wp_authors_directory($args = '') {

	global $wpdb;
	$my_base = get_bloginfo('url');

	$defaults = array(
		'optioncount' => false, 'exclude_admin' => true,
		'show_fullname' => true, 'hide_empty' => false,
		'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true
	);

	$r = wp_parse_args( $args, $defaults );
	extract($r, EXTR_SKIP);

	/** @todo Move select to get_authors(). */
//	$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");

	$authors = $wpdb->get_results("SELECT ID, user_login, meta_key, meta_value from {$wpdb->users} LEFT JOIN {$wpdb->usermeta} ON {$wpdb->usermeta}.user_id = {$wpdb->users}.ID WHERE {$wpdb->users}.user_login NOT LIKE 'unverified%' AND meta_key LIKE 'last_name' ORDER BY meta_value");

	foreach ( (array) $authors as $author ) {
		$author = get_userdata( $author->ID );
		$name = "$author->first_name $author->last_name";
		$image = $author->userphoto_thumb_file;
		$image_width = $author->userphoto_thumb_width;
		$image_height = $author->userphoto_thumb_height;
		$company = $author->company;
		$category = $author->business_category;
		$network_role = $author->network_of_tacoma_role;
		$phone = $author->phone;
		$fax = $author->fax;
		$email = $author->user_email;
		$website = $author->user_url;
    $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Details About %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>';

    if ($website == null ) {
      $website = 'mailto:' . $email;
    }

    if ($image == null ) {
      $image = 'no_photo.gif';
    }

    echo '<div class="member clearfix">
            <div class="member-thumb">
              <a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Details About %s"), attribute_escape($author->display_name)) . '"><img src="' . $base . '/wp-content/uploads/userphoto/' . $image .'" width="' . $image_width . '" height="' . $image_height . '" alt="' . $name . '" /></a>
            </div>
            <div class="member-details">
              <h3>' . $link . '</h3
              <dl class="clearfix">
                <dt>Company</dt>
                  <dd><a href="' . $website . '" target="_blank">' . $company . '</a></dd>
              </dl>
              <dl class="clearfix">
                <dt>Business Category</dt>
                  <dd><a href="' . $website . '" target="_blank">' . $category . '</a></dd>
              </dl>
              <dl class="clearfix">
                <dt>Network Role</dt>
                  <dd>' . $network_role . '</dd>
              </dl>
              <dl class="clearfix">
                <dt>Phone</dt>
                  <dd>' . $phone . '</dd>
              </dl>
              <dl class="clearfix">
                <dt>Email</dt>
                  <dd><a href="mailto:' . $email . '">' . $email . '</a></dd>
              </dl>
              <p><em>More about ' . $link . '</em></p>
            </div>
          </div>'
          ;

	}
}

Directory page template code:

<?php
/*
Template Name: Directory Template
*/
?>

<?php get_header(); ?>

			<div class="left-column">
<?php include('side-main.php'); ?>
			</div>
			<div class="right-column">
        <?php wp_authors_directory(); ?>
			</div>
		</div>
  </div>
<?php get_footer(); ?>

wazzaday on "Hiding certain posts based on a condition"

$
0
0

I have a custom post type, called users, when a post is generated (via front end) it is given a date 5 days in the future. I want to hide all posts in the dashboard that are not 5 days old yet, and only have them appear after that. Any ideas?

rchak2000 on "Add categories as class in function"

$
0
0

I'm having trouble adding a list of category name classes to the first LI. Ideally, i'd like the HTML output to be <li class="category1 category2 category3">. I've messed around with the get_the_category function but can't seem to get it to work in this syntax. Anyone out there have any tips?

$posts = get_posts("numberposts=" . $numberposts . "&orderby=" . $orderby . "&post_parent=" . $post_parent . "&post_type=" . $post_type . "&category=" . $category . "&tag=" . $tag);

           if($posts) {
                  foreach($posts as $post):
                          setup_postdata($post);

				$metadata = get_post_custom( $post->ID );			

		   	$return .= '<li>
                                            <a href="javascript:;">
                                                <h3>' . get_the_title($post->ID) . '</h3>
                                                <span>' . $metadata['feature_slideshow_description'][0] . '</span>
                                            </a>
                                        </li>';

									endforeach;
                                }

                        $return .= '</ul>

mvandemar on "How to remove title and content boxes from a custom post type?"

$
0
0

Is there a way to eliminate the Title and Content boxes from a custom post type? I am setting up an inventory that has a Part Number, which I would like labeled accurately in the interface, and a part description, which is less than 255 characters and has no need of a rich text box to edit. If I omit the 'supports' element or set it to an empty array in the register_post_type() $args array they both show up anyway.

Thanks.

-Michael

Mark Jansen on "Changing sample permalink"

$
0
0

Hello all,

I have made myself a custom rewrite for a post type I've made. All 's well and all 's fine, but I run into a slight problem.

When the post is auto saved, the permalink structure does not show correctly in the sample permalink under the title.

It shows as http://loc.test-site.org/?post_type=matches&p=137 where with my code I expect it to be: http://loc.test-site.org/match/%d%/%m%/%Y%/%post-name%/

If I save the post, it all works fine, but when it autosaves it's not.

Anyone have any idea how I can fix this?

I use the code below to generate my new permalink

function better_match_permalinks( $permalink, $post ) {
	global $wp_rewrite;

	$timestamp = get_field( 'match_datetime', $post->ID );

	$structure = __( 'match', 'apollo' );
	if( ! empty( $timestamp ) ) {
		$structure .= date( '/d/m/Y', $timestamp );
	} else {
		$structure .= date( '/d/m/Y', strtotime( $post->post_date ) );
	}
	$structure .= '/%matches%/';
	$wp_rewrite->add_rewrite_tag( "%matches%", '([^/]+)', "matches=" );
	$wp_rewrite->add_permastruct( 'matches', $structure, false );

	return $permalink;
}

I hope some one can help me out.

Thanks

Mark

Viewing all 8245 articles
Browse latest View live




Latest Images