New answers tagged

0

To achieve something like that you can make some posts private and show them just to the logged in users, first you need to add a custom field, you can name it "private" and value it "True". Then add replace the default WP loop with this code snippet: <?php if (have_posts()) : while (have_posts()) : the_post(); $private = ...


0

This is a simpler code for getting all posts on your site. <?php while(have_posts()) : the_post(); ?> <ul> <?php $allposts = get_posts('numberposts=-1&offset=0'); foreach($allposts as $post) : ?> <li><?php the_time('d/m/y'); ?>: <a href="<?php the_permalink(); ?>"><?php the_title(); ...


0

Add this code to your functions.php function mdc_remove_img($content) { $content = preg_replace("/<img[^>]+\>/i", "", $content); return $content; } add_filter( 'the_content', 'mdc_remove_img' );


-4

I figured out how to do this, Instead of using the_content(); Im now using the_excerpt(); and Im just changing the amount of characters it brings through!


0

You can set post featured image space with css. like this: img.featured_image{ width: 50px; height: 50px; }


3

First, you should always use the WordPress AJAX methods, not a custom function for that. See AJAX in Plugins in the Codex. With that practice in mind, you can set up your request like this. Change the AJAX URL to <?php echo admin_url('admin-ajax.php'); ?> and add the actionyou want WordPress to execute in the next step to your data . ...


0

I have done the same with get_posts() method. Here is the code i used to get posts on my page. I was filtering my Posts according to their categories, so i gave the category slug in category_name, you can leave it blank if you want all your posts to be shown. <?php $args = array( 'posts_per_page' => 5, 'offset' => 0, ...


0

Try this: function shortcode_func( $atts ) { ob_start(); echo 'shortcode output'; $output = ob_get_contents(); ob_end_clean(); echo $output; // Here comes the total output of your shortcode } add_shortcode( 'shortcode', 'shortcode_func' );


0

i have found this code: define('my_revisions_amount', 1); // let keep only one revision define('my_autosave_interval', 600); // 600 minutes is enough if (IS_ADMINN){ add_filter( 'wp_revisions_to_keep', function(){return my_revisions_amount;} ); add_filter( 'wp_print_scripts', function(){wp_localize_script( 'autosave', 'autosaveL10n', ...


0

I would check that your users have the same capability. It sounds like this is happening: "Internally, WordPress sets the post status to publish when you click the "Publish" button, and WordPress sets the post status to draft when you click the "Save Draft" button. Similarly, if your website has users granted the edit_posts capability but not the ...


0

You need to have your website properly setup to retrieve content and links. You can use a plugin like Yoast SEO to help you generate the correct OG meta tags to do this Additionally if you have those tags setup and it is not displaying properly then you can force facebook to re-crawl the page by going to https://developers.facebook.com/tools/debug/ and ...


2

The theme uses the_excerpt() instead of the_content(). I had created a child theme before (so I don't modify the source theme directly: only the child one), so I only had to copy/paste the PHP file (archive.php) from source theme to child theme, and change the_excerpt() for the_content( __( 'Read more &#8250;', 'my-domain' ) );


-1

The answer it seems was using 'RAND' instead of 'rand'.


0

I ended up just setting the paragraph to display:inline-block which allowed the product dimensions to flow up onto that line.


0

you may get the excerpt using: $excerpt = get_the_excerpt(); and append or prepend it as you wish


-1

Number of items per page was set to 1! Problem solved


0

This is adapted from code someone else wrote, and which I benefitted from too long ago to know where it came from (if the person who originally wrote it is reading this, thanks again). It works for your request: <?php $catPost = get_posts('cat=888&posts_per_page=-1000'); foreach ($catPost as $post) : setup_postdata($post); ?> <a ...


0

So this is the code I have on one of my Website inside the footer, this basically get's the 3 latest posts and displays the_title you can change this to show the_excerpt. <?php // news posts loop begins here $newsPosts = new WP_Query('page=blog&posts_per_page=3'); if ($newsPosts->have_posts()) : while ($newsPosts->have_posts()) : ...


1

You most probably ran into problems with escaping code and HTML from each other. Try this (added line breaks just for better readability): <i class=" <?php echo (get_post_meta(get_the_ID(), 'Preis', true) != '') ? 'fa fa-check' : 'fa fa-times'; ?> ">


0

The method I prefer to use is just a bit shorter then the previous answer. <php $myExcerpt = wp_trim_words( get_the_content(), 20, '' ) ; echo $myExcerpt ; ?> The WordPress function wp_trim_words() returns only text (no images). wp_trim_words ( string $text, int $num_words = 55, string $more = null )


0

If I understand your problem then this should definitely work. <?php get_header(); $users = get_users( array( 'who' => 'author' ) );//get all the users with author role in an array foreach ( $users as $user ) { //travers the array if($user->caps['administrator']==1)continue; // skip the user if user also have administrative ...


0

I finally managed to accomplish the task using XML-RPC as suggested by denis.stoyanov. If xmlrpc is installed on your Server simply use the wpPostXMLRPC function from stackoverflow. But keep in mind that the used xmlrpc_encode_request() is an experimental function you usually would try to avoid.


0

Setup a script on site.com to receive the data from input.com and use wp_insert_post() to create the post on site.com. The title, content and other post details are sent using the following array structure: $post = array( 'ID' => [ <post id> ] // Are you updating an existing post? 'post_content' => [ <string> ] // The ...


0

You can put together a very finite query with the get_posts() function. I tried to understand your SQL query and define it the way I would with native WP functionality, but could have missed some details. I have no clue if this is where you are going, or if this works, but WordPress is supposed to make things easier for you. Explore this page for more info. ...


0

Try the answer here: http://stackoverflow.com/a/13575967 To repeat the code from that answer: function featured_image_requirement() { if(!has_post_thumbnail()) { wp_die( 'You forgot to set the featured image. Click the back button on your browser and set it.' ); } } add_action( 'pre_post_update', 'featured_image_requirement' );


0

When inserting images into posts and pages in WP 4.4, change the Link To under ATTTACHMENT DISPLAY SETTINGS to None.


1

Note that if you have the post slug, you don't need the additional taxonomy query to find that post, so it makes sense to drop the expensive taxonomy query in core in that case. Otherwise you could try instead the post_name__in parameter: [ 'post_name__in' => [ '<postslug>' ], 'tax_query' => [ [ 'taxonomy' ...


2

SQL-wise, you only need to join to the wp_posts table once. Joining to the terms stuff will give you multiple rows, so it's probably easiest to group these and then use GROUP_CONCAT() to flatten the terms into a comma-separated string (updated to use LEFT joins): global $wpdb; $sql = $wpdb->prepare( 'SELECT p.ID, p.post_title AS Product, ...


0

A quick and easy way would be to just run a search on your Wordpress site on the name of the image. E.g. your-image.png. This should return a list of all the posts which have that image in it.


2

cracks knuckles Alright -- so first thing is first. Working w/ WordPress Databases Read this: https://codex.wordpress.org/Class_Reference/wpdb Avoid write SQL statements outside of the $wpdb object. Avoid writing SQL statements like wp_users instead do this: $users = $wpdb->get_results( "SELECT FROM $wpdb->users" ); This will help if you ever ...


-2

You could remove it with jQuery this way: jQuery('.zoomthumbnail-image').next('br').remove();


8

UPDATE 21-01-2016 19:35 SA TIME - BUG FOUND!!!!! YEAH!!!!!! I finally found the bug. As you stated in your last update, the failure only happens when $post_content has a <!--nextpage--> tag in the content. I tested it, and did confirm that any other page after the page after the <!--nextpage--> returns a 404 and then the page gets redirects back ...


1

You want a filter on pre_get_posts restricted to the home page. Something like: function pregp_wpse_214875($qry) { if (is_home() && $qry->is_main_query()) { $qry->set('order','ASC'); } } add_action('pre_get_posts','pregp_wpse_214875'); You may need something other than is_home(), depending on how your "home page" is set up. The other ...


0

Make sure you have the Text / HTML tab selected when you input HTML, not the Visual tab.


0

It's possible to capture the $post_id using a combination of wp_get_referer() and url_to_postid() then reset the $post using setup_postdata. That should work easy enough for the front-end. But on the admin side we'll need to pull the query with parse_url and grab the ID using parse_str. For good measure we should double check if we're editing a post by ...


1

I've managed to get the following to work. Let me describe the technique so that you can decide whether or not to use it. the code uses two hooks, one fired just before the "side" meta boxes get placed, and another immediately after the "date/time" section in the publish meta box. the first hook (before) records the original post type, and then switches it ...


0

When you use the graphical interface, post_name is stored in the wp_posts table even for draft posts as soon as you modify the default value. I tried your code (case 2) and I actually see the new entry in the database, with the correct post_name. Perhaps your check to post_name is not correct ?


3

There are several ways to deal with this problem. You could have a look for some syntax highlighter plugin, those will also bring you coloured text with highlighted keywords etc. pp. This is probably nice, if you use code quite often. I use SyntaxHighlighter Evolved. If you want to do this by hand, <code> is probably the HTML-element you want to use, ...


0

This is pretty simple. So simple you need to make sure your guests don't insert bad code into you DB. So read up on Data Validation and Validating Sanitizing and Escaping User Data before you add anything to your site from a front-end form. Create a new page at /new-post Create a page template to target that page Setup AJAX actions Render your form inside ...


2

Use the following for with Custom Text with Link. The above given code by @TheDeadMedic works only with text but no link. Code With Link and Custom Text like this: <?php previous_post_link( '%link','Previous Post' ) ?> <?php next_post_link( '%link','Next Post' ) ?> Hope this helps.


0

There's no need for multiple queries - posts are, by default, ordered by most recent. Just apply a classname for the first post on the first page: <article <?php post_class( $wp_query->current_post === 0 && ! is_paged() ? 'my-awesome-first-post' : '' ) ?> The first post of the first page will have the class my-awesome-first-post. ...


0

There's no hook for "give me a post ID before the post has been created". You only get an ID after the post has been saved. So yes, use the hook 'content_save_pre' to modify your content before saving, then once you get back a post ID use that ID to update the post featured image. There's a great answer describing how to acquire and set the image for a ...


0

I used JQuery to fix this problem and target the specific elements. In particular, I used: wrap, wrapInner, wrapAll, replaceWith, unWrap, and remove.



Top 50 recent answers are included