Tag Info

New answers tagged

0

Paste this into your theme's functions.php file. Then put [contact_form] shortcode into the Page where you want contact form to appear. And there is send_contact_form() function that will process data when form is submitted. if( !session_id() ) session_start(); function contact_form( $atts = array() ) { global $post; $return_url = ...


1

First of all: do not use query_posts use get_posts or new WP_Query instead. If you want to show only most viewed posts, you'll need to add action ( for ex. wp ) check if your on single post page and update that post meta views ( +1 ). Then you could do something like these $topViewedPosts = new WP_Query( array( 'post_type' => 'post', 'meta_key' ...


0

You want to isolate what changes were made that caused the issue. If there is any way of narrowing down when the problem started - i.e. after what code or plugin changes - that would be my first stop. If you can't think of any suspects: Look in your browser's Javascript console and see if an error pops up when you try and publish the post. If so, the ...


0

From a search engine perspective, two of these answers combined will help Google to track the hierarchy of your posts, as well as users of course. Add a page and use it to host your posts. "The best way to set a parent page through all of your posts is through the (Appearance -> Customize) menu. You can set a static page for your home page or posts page. ...


3

You can use the has_password parameter of WP_Query. Here's an example how you can hide it, for non administrators, on the edit.php screen for the post post type: /** * Hide password protected posts, for non-admins, in the case of 'edit-post' screen id * * @link http://wordpress.stackexchange.com/a/200426/26350 */ add_action( 'pre_get_posts', function( ...


0

You can add button via add_meta_box function. function add_your_meta_box(){ add_meta_box('your-metabox-id', 'Title', 'function_of_metabox', 'custom_post_type', 'side', 'high');} add_action('add_meta_boxes', 'add_your_meta_box'); function function_of_metabox() {?> <input type="submit" class="button button-primary button-large" value="Add New" ...


2

Like this: function custom_js_to_head() { ?> <script> jQuery(function(){ jQuery("body.post-type-YOUR-CUSTOM-POST-TYPE .wrap h1").append('<a href="index.php?param=your-action" class="page-title-action">Import from ...</a>'); }); </script> <?php } add_action('admin_head', 'custom_js_to_head'); ...


1

$ids = get_users( array('role' => 'author' ,'fields' => 'ID') ); $contr_limit = count($ids); for($cntr=0; $cntr < $contr_limit; $cntr++){ if( pmpro_hasMembershipLevel($level_id, $ids[$cntr] ) !== true ){ unset($ids[$cntr]); } } $args = array( 'author' => implode(',', $ids), 'orderby' => 'date', ...


0

You can create a Page template in which display all posts with your custom markup. <?php /** * Template Name: My Custom Blog * */ // The Query $args = array('posts_per_page'=>-1); $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { ...


2

WordPress 4.3 have no markdown implementation, it is only a short list of shortcuts. The shortcuts active on default. It give no UI area to active/deactivated them. As small hint for updates posts. I seen often, that works only on new posts, no old drafts. But I haven't debug this. Which Formatting Shortcuts WordPress 4.3 came with a new feature called ...


1

Depending on your needs, WP Query may not work for this since it won't include posts that have been deleted after the trash has been emptied. This should work (but hasn't been tested): function wpse_custom_post_type_counter() { $number = get_option( 'wpse_custom_counter' ) ? absint( get_option( 'wpse_custom_counter' ) ): 0; $number++; ...


0

Presuming you don't empty the trash on deleted posts, you can do it with a simple wp_query. <?php $args = array ( 'post_type' => array( 'your-custom-post-type' ), 'post_status' => array( 'publish', 'trash' ), 'posts_per_page' => -1 ); $query = new WP_Query( $args ); $total = count($query->posts); ?> <h1>My ...


0

Try this code (maybe working) , but i'am not sure cause not testing : function amin_show_expire(){ global $wpdb; $result = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_type = 'CUSTOM' AND post_status = 'publish'"); if( !empty($result)) foreach ($result as $a){ $show_time = get_the_time("Y-m-d", $a->ID ); ...


0

Although I haven't tested it, a quick search revealed this (new) plugin which claims to do what you want: https://wordpress.org/plugins/publish-post-email-notification/ Publish post notification is plugin which will send automatic email when the post is published and approved by WordPress blog. admin have to go to setting and set email template thats it ...


0

What about add else { after get_template_part( 'template-parts/content', 'video'); }? EDIT (1) : <?php /** * The template for displaying single posts. * * @package SN */ get_header(); ?> <?php while ( have_posts() ) : the_post(); ?> <?php if( has_post_format('video')) { get_template_part( 'template-parts/content', 'video'); }else{ ...


0

This can be achieved by using the admin_url filter: function add_new_post_url( $url, $path, $blog_id ) { if ( $path == "post-new.php" ) { $path = "post-new.php?param=value"; } return $path; } add_filter( 'admin_url', 'add_new_post_url', 10, 3 );


0

Try the following: Disabled all plugins, removed plugins folder entirely - problem still persists. Removed the .htaccess file - problem still persists. Tried a fresh install - problem still persists. Cleared browser cache. Checked the server for any auto updates - there haven't been any. Changed the autosave to various times define( ...


0

For a specific custom taxonomy try: $the_query = new WP_Query( array( 'post_type' => 'CUSTOM_POST_TYPE', 'tax_query' => array( array( 'taxonomy' => 'CUSTOM_TAXONOMY', 'field' => 'id', 'terms' => TERM_ID ) ) ) ); $count = $the_query->found_posts; Documentation at ...


0

You just need to add this to your theme's functions.php file: /** * Attach a class to linked images' parent anchors * e.g. a img => a.img img */ function give_linked_images_class($html, $id, $caption, $title, $align, $url, $size, $alt = '' ) { $classes = 'img'; // separated by spaces, e.g. 'img image-link' // check if there are already classes ...


0

By default the user can only edit their comments for the first 5 minutes. After that, the user is not able to edit their comment. If you want to change this time period, then this plugin allows you to do so using a filter. Simply add the following code in your theme’s functions.php file or in a site-specific plugin like this: add_filter( 'sce_comment_time', ...


0

In your loop, you can use a variable to check, in this case $i, so the code will belong to: <?php $the_query = new WP_Query( 'showposts=7&cat=113' ); ?> <?php while ($the_query->have_posts()) : $the_query->the_post(); ?> <strong><a href="<?php the_permalink() ?>"><?php the_title(); ...


0

Here's a start (Function found here); function getPostViews($postID){ $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return "0 View"; } return $count.' Views'; } function ...


0

To me you code looks good, I would recommend adding priority as high as 9999 Heres how : add_filter('the_content', 'filter_ptags_on_images', '9999');


-1

Try this. Open your functions.php file and add the following PHP snippet remove_filter('the_content', 'wpautop');


0

At least in Chrome and Firefox you can enter about:cache and start digging there. With some luck you might still find something. Unfortunately I can't give you a more detailed instruction as I've never done this before myself. Also if you plan to follow that path you are not too likely to be helped here on WPSE as this isn't a WordPress issue now any more.


0

No, if you've emptied the Trash you can't recover anything from it (and note after 30 days in trash, a post will be permanently deleted.) If you have database backups, you can restore a draft from the wp_posts table (look for records with post_status = "draft" and grab the post_content field. https://en.support.wordpress.com/deleted-posts-and-pages/


2

Add following code in your theme's functions.php. // To add extra column in column headers add_filter('manage_posts_columns', 'bs_event_table_head'); function bs_event_table_head( $defaults ) { $defaults['pending_comments'] = 'Pending Comments'; return $defaults; } // To add data in column for each post. add_action( 'manage_posts_custom_column', ...


1

It's a UNIX timestamp - with PHP, you can use date to format it like so: echo date( 'd/m/Y', $timestamp ); // day/month/year


0

There is a plugin that regenerates the urls for post/pages/attachments! You can also go to permalinks and select 'default' or custom structure using post id. This hack is only for pages/post not attachments.


3

I was curious about this and checked the Codex on keyboard shortcuts, but didn't find it mentioned there. I searched and found out that this seems to be already solved, e.g. here and here. I haven't tested out these other plugins so I'm not sure how they solve it, but I decided to take on the challenge and see how this could be solved ;-) So here's my ...


0

WordPress has a is_single() function to check for this very condition inside the loop. function wpse_75691_trim_words( $title ) { if( is_single() ) { return $title; } return wp_trim_words( $title, 10, '' ) . ' ...'; } There is a fairly robust list of conditional tags in the Codex.


0

You can add custom classes to each post. Here is a quick example of one approach: add_action('post_class','YOURNAME_post_class'); function YOURNAME_post_class( $classes ) { global $wp_query; if( ! $wp_query->is_main_query() ) return $classes; $classes[] = 'class-on-all-posts'; if( 0 == $wp_query->current_post || 0 == ...


0

Use meta_query argument in the array. $custom_post_type = 'event'; $args = array( 'post_type' => $custom_post_type, 'post_status' => 'publish', 'meta_key' => 'event_date_and_time', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'posts_per_page' => -1 'meta_query' => array( array( 'key' ...


0

You can use meta_query, if you date information is saved in custom field. Like this: $args = array( 'post_type' => $custom_post_type, 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'event_date_and_time', 'value' => current_time('Ymd'), 'compare' => '>=' ) ...


0

wp_get_post_categories can only get POST categories not a custom post's categories, try this instead: $category = get_the_terms( $post->ID, 'custom-taxonomy-here' ); foreach ( $category as $cat){ echo $cat->name; } Check this link


0

You can assign a class with JavaScript to the paragraph tag if it has an img: jQuery: $(".entry-content p").each(function(){ if($(this).find("img").length > 0) $(this).addClass("has-img"); } then just add a css rule: p.has-img{ width: 100%; }


0

Okay I hate it when I just figure it out after I post the question. But it seems each post can have a number of attachments. Which means each attachment has an ID associated with it. Which was confusing because it shared the same ID style and type as the post. The following code is able to get the URL of the associated uploaded image $media = ...


0

you should use get_post_meta( $post_id, '_custField1', true ); make $single parameter true so it will return a single value.


0

This is how I would do it... $page_list = get_pages(); foreach($page_list as $page) { $post_id = $page->ID; $custArray = array( '_custField1' => get_post_meta( $post_id, '_custField1', true ), '_custField2' => get_post_meta( $post_id, '_custField2', true ), '_custField3' => get_post_meta( $post_id, ...


0

You can try the following function: function enable_comments() { update_option( 'default_comment_status', 'open' ); } add_action( 'after_setup_theme', 'enable_comments' ); This should enable comments for all new posts. On the other hand have you checked your theme? Some themes for some reasons have build in functions that overrides the default WP ...


0

That code should work. I just tested in my own index.php and it worked. Are you sure you're looking at the index.php file. Sometimes WP actually pulls a different template: For more info, see WP template hierarchy diagram. To test what template you're seeing, place this code in your functions.php file temporarily: add_action('wp_head', 'show_template'); ...


1

You could use this search and replace tool: search and replace by interconnectit Apart from that you could put some redirects in your htaccess, but really the search and replace works great.


0

I believe the issue is this line: if( $post->post_type == 'startups' ) return; Won't your custom posts always have the type startups? Basically you are telling your code that whenever I save my custom post type, ignore my custom fields. You probably meant to have one of the WP reserved types (e.g. revision or attachment) that would prevent your ...


0

Thank you for your answer, yes i don't have a good level in javascript but i have created the same thing that you said and its worked but its need the animation so i tried to be based on flex slider but without any success thats my code, i know that this code is for attachement but i don't have anything shown. function revconcept_get_images($post_id) { ...


0

I think the problem is you don't know how to use the slider plugins you choose. In fact if you know JavaScript, you could make a simple slider without jQuery. To create a post slider, the steps is: 1: Create a post list by WordPress function. Use a <ul> label to wrap the list and use <li> label wrap every post: <div ...


0

If you don't mind the cost of calling COUNT to first get the total number of posts (you have a dynamic first page in terms of numbers of posts so it doesn't work with a simple offset) here is something that I've wrote (it's late and I am tired so it might have some bugs / might not be the right solution): // This code can be placed in the 'functions.php' ...


1

I have gone through your code and found that the function longform_the_related_posts displays 8 related posts. This function is defined in functions.php of parent theme and called in single.php. Thus, to override the function, follow below steps - 1. Create another function that displays 4 related posts in functions.php of child theme. (As you have ...


1

My suggesion is to use wp_localize_script() to pass the post id to your AJAX calls. Something like this.. function my_script_enqueue() { global $post; $translations = array( 'postID' => $post->ID ); wp_enqueue_script( 'myscript', '/url/to/your/script.js', array('jquery') ); wp_localize_script( 'myscript', 'MyAJAX', ...


1

As you can see, I tried declaring the $post variable as global to account for failures due to being outside of the Loop. The problem is not that the post is "outside of the loop", problem is that AJAX request is a completely separate HTTP request. When you do an AJAX request, is just like you are opening a new window on browser and open the url in ...


0

What about sending the post id of the single post trough ajax as well? So if you create a hidden input that contains the id, something like this: <input type="hidden" id="post_id" name="post_id" value="<?php echo $post->ID; ?>"> Then you can just pick the id and send it trough the ajax request, so your function will end up looking ...



Top 50 recent answers are included